It definitely looks like a bug. A byte ranges from -128 to 127, not from 0 to 255.
Here is what I think is happening with the byte value -1 (i.e. 0Xff), where it prints 255 instead:
public static void main(final String... args) { final ByteBuffer buf = ByteBuffer.allocate(4);
That is, when "boosting" from byte to int, any Java compiler you use does not do what JLS requires, that is, to carry a signed bit.
I seriously doubt that the Oracle JDK compiler / runner is used on the command line for this purpose.
(note that a PrintStream has a method for printing int , but not byte , so the byte advances to int)
source share