8245121: (bf) XBuffer.put(Xbuffer src) can give unexpected result when storage overlaps
Paul Sandoz
paul.sandoz at oracle.com
Fri May 29 16:25:12 UTC 2020
There we go :-) I found it took me a couple rounds of writing tests to settle on a few useful patterns. Generally it would be useful if we had a test library for creating combinations, permutations, zipping etc. (CC’ing Pavel)
I have one other request and one comment, both of which you can choose to ignore if you wanna wrap this up.
- change the implementations of MyRandom.next$Type to use next(<size-of-type-in-bits>) rather than your use your own shifting logic.
- typeToAttr can be constructed using Map.of:
Map.of(
byte.class, TypeAttr.of(ByteBuffer.class, Byte.BYTES, “Byte”),
char.class, …
…,
)
In fact TypeAttr really really wants to be a record (nominal tuple). I believe we can use preview features in tests, and it is worthwhile to do so (gaining more coverage).
Paul.
> On May 28, 2020, at 5:57 PM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
>
>
>> On May 28, 2020, at 5:21 PM, Paul Sandoz <paul.sandoz at oracle.com <mailto:paul.sandoz at oracle.com>> wrote:
>>
>> Here’s a tip, rather than creating a fixed size array upfront:
>>
>> - create a List<Object[]> to add argument list combinations to
>> - add with args.add(new Object[] {proxy})
>> - at the end do args.toArray(Object[][]::new)
>
> Cool - thanks!
>
>> For:
>>
>> 281 List<BufferProxy> proxies1 = getProxies(type);
>> 282 List<BufferProxy> proxies2 = getProxies(type);
>> 283 for (BufferProxy proxy1 : proxies1) {
>> 284 for (BufferProxy proxy2 : proxies2) {
>> 285 data[index][0] = proxy1;
>> 286 data[index++][1] = proxy2;
>> 287 }
>> 288 }
>>
>> Can you reuse proxy1 since the list is not modified and the proxy is stateless w.r.t. Buffers? Is it necessary to test when proxy1 == proxy2 i.e. the diagonal?
>
> Good point. Yes I think it can be re-used as there is no relevant state. I don’t think it’s necessary to check for proxy1 == proxy2: we want to test the case where both are the same type, kind, and order.
>
>> It’s useful to try the streams approach as an exercise, I can imagine some people might find nested flatMaps a little jarring. The nested loops are fine here.
>
> The updated version is at
>
> http://cr.openjdk.java.net/~bpb/ <http://cr.openjdk.java.net/~bpb/>8245121/webrev.04/
>
> It keeps getting shorter!
>
> Thanks,
>
> Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20200529/6dff6db7/attachment.htm>
More information about the nio-dev
mailing list