Based on the article here, compareTo method on the ByteBuffers might not work correctly when dealing with negative numbers
bytes in Java are signed, contrary to what one typically expects. What is easy to miss
though, is the fact that this affects ByteBuffer.compareTo() as well. The Java API
documentation for that method reads:
"Two byte buffers are compared by comparing their sequences of remaining elements
lexicographically, without regard to the starting position of each sequence within its
corresponding buffer."
A quick reading might lead one to believe the result is what you would typically expect,
but of course given the definition of a byte in Java, this is not the case. The result
is that the order of byte buffers that contains values with the highest order bit set,
will diverge from what you may be expecting.
I tried a couple of examples of putting negative values into the buffer, and comparing with positives, it was always OK. Is the article speaking of the case when we e.g. read in binary data, when an integer -1
was stored as 100000...001
and that would cause issues?