RFR 9: 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN

Alan Bateman Alan.Bateman at oracle.com
Thu Dec 4 14:09:03 UTC 2014


On 03/12/2014 21:43, Brian Burkhalter wrote:
> Please review at your convenience.
>
> Issue:	https://bugs.openjdk.java.net/browse/JDK-8065570
> Patch:	http://cr.openjdk.java.net/~bpb/8065570/webrev.00/
>
> One interesting thing not part of this patch is that the byte order of the ByteBuffer returned by ByteBuffer.asReadOnlyBuffer() is always BIG_ENDIAN, whereas that of the XBuffer returned by XBuffer.asReadOnlyBuffer() is the byte order of the original XBuffer. This seems inconsistent. For instance, this code sequence
>
>          ByteBuffer buf = ByteBuffer.allocate(256);
>          buf.order(ByteOrder.LITTLE_ENDIAN);
>          System.out.println(buf.asIntBuffer().asReadOnlyBuffer().order());
>          System.out.println(buf.asReadOnlyBuffer().asIntBuffer().order());
>
> will print
>
> LITTLE_ENDIAN
> BIG_ENDIAN
>
I think you'll need to dig into inconsistencies before we add any 
clarifications to the javadoc. I assume any issues date back to JDK 1.4 
but we need to check that. I don't have time to dig into myself just now 
but I believe the original intent was that all new buffers be created in 
BIG_ENDIAN and that view buffers are tied to whatever the order is of 
the byte buffer that they are created.

-Alan


More information about the nio-dev mailing list