8245121: (bf) XBuffer.put(Xbuffer src) can give unexpected result when storage overlaps

Paul Sandoz paul.sandoz at oracle.com
Fri May 29 00:21:59 UTC 2020


Much better!

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)

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?



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.

Paul.

> On May 28, 2020, at 4:56 PM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
> 
> 
>> On May 28, 2020, at 1:40 PM, Paul Sandoz <paul.sandoz at oracle.com <mailto:paul.sandoz at oracle.com>> wrote:
>> 
>>> I took a stab at changing the test to use DataProviders and Asserts in this update.
>>> 
>> 
>> That’s a good start, but I think the use of iterators in this case makes it more complicated than need be. Iterators are a pain to directly compose, its hard to see the cross product.
>> 
>> A data provider can return Object[][], basically an array of test case arguments, if you are not concerned about the pre-allocation of the number of cases (which I think is so here). So you can use your favorite nested for loops, or nested streams and flatMap if you wish to do something lazily, to construct the test argument set.
> 
> An updated version is at
> 
> http://cr.openjdk.java.net/~bpb <http://cr.openjdk.java.net/~bpb>/8245121/webrev.03/.
> 
> This gets rid of the Iterators in favor of nested for loops. It’s about 90 lines shorter than the previous version. I might try nested streams and flatmap later for educational purposes.
> 
>> For the testPairs method you can separate out the arguments, no need for an array.
> 
> Fixed.
> 
> Thanks,
> 
> Brian

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20200528/2e7218c9/attachment-0001.htm>


More information about the nio-dev mailing list