Hi,
I checked on my side.
- Using JDK (Oracle) 8 1.8.0_221 (Linux)
- Using OpenJDK 8 1.8.0_232 (Linux)
- Using both Netty 4.1.50
Both versions gives 0 bytes initialized ByteBufs.

However, in general, assuming an allocation gives a zero values array is a 
wrong assertion (at least in many languages).

If you want to ensure your ByteBuf is set to 0, allocate as you do and then:

  byteBuf.setZero(byteBuf.readerIndex(), SIZE);

Cheers,
Frederic
Le mercredi 20 mai 2020 20:38:27 UTC+2, Priyanka Perera a écrit :
>
> Hi,
>
> It appears that with *openjdk-11.0.3* the *Unpooled.buffer()* may return 
> a *ByteBuf *with a backing array elements initialized to non zero values.
>
> In Oracle JDK 8 however, the elements of the backing array are initialized 
> to zero. 
>
> Using *netty-4.1.41.Final*.
>
> Appreciate if this can be explained.
>
> Is there an API to get a ByteBuf with backing array elements initialized 
> to zero ?.
>
> @Test(invocationCount = 10000)
> public void testInitialization() {
>     final int SIZE = 10000;
>     ByteBuf byteBuf = Unpooled.buffer(SIZE);
>
>     int arrayLength = byteBuf.array().length;
>     for (int arrayIndex = 0; arrayIndex < arrayLength; arrayIndex++) {
>         Assert.assertEquals(byteBuf.array()[arrayIndex], 0);
>     }
> }
>
>
> [image: image.png]
>

-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/9e526b19-3db8-4f4f-9bb7-977c5315dcfc%40googlegroups.com.

Reply via email to