Name: nt126004 Date: 07/15/2002 FULL PRODUCT VERSION : java version "1.4.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92) Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode) FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000 [Version 5.00.2195] A DESCRIPTION OF THE PROBLEM : The byte ordering of a ByteBuffer created by the duplicate method is always BIG_ENDIAN even if the original buffer was LITTLE_ENDIAN. This is very surprising behaviour. The slice () method also shows this behaviour. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Run the attached test code! 2. 3. EXPECTED VERSUS ACTUAL BEHAVIOR : I would expect the duplicate of a buffer with LittleEndian byte ordering to also have litte endian ordering. The actual output from my test is original BIG_ENDIAN, duplicate BIG_ENDIAN original LITTLE_ENDIAN, duplicate BIG_ENDIAN original BIG_ENDIAN, duplicate BIG_ENDIAN original LITTLE_ENDIAN, duplicate BIG_ENDIAN The first pair relate to a heap allocated buffer, while the second pair to a direct allocated buffer. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.nio.*; class TestByteOrder { public static void main(String[] args) { ByteBuffer a = ByteBuffer.allocate(1024); System.out.println("original "+a.order()+",duplicate "+a.duplicate().order()); a.order(ByteOrder.LITTLE_ENDIAN); System.out.println("original "+a.order()+",duplicate "+a.duplicate().order()); a = ByteBuffer.allocateDirect(1024); System.out.println("original "+a.order()+",duplicate "+a.duplicate().order()); a.order(ByteOrder.LITTLE_ENDIAN); System.out.println("original "+a.order()+",duplicate "+a.duplicate().order()); } } ---------- END SOURCE ---------- CUSTOMER WORKAROUND : Either always use BIG_ENDIAN byte ordering or set the desired ordering after each duplicate or slice call. (Review ID: 158553) ======================================================================
|