Hi,
There is a bug in getUserVersion()
method of Java Bindings, due to <<
having higher precedence over ‘&’ . Please see the test below that will show the bug, and the fixed behavior.
Please let me know if I should file an issue for this and submit a patch?
@Test
public void testUserVersion() {
final byte[] tv = {
(byte) 0xaa, (byte) 0xbb, (byte) 0xaa, (byte) 0xbb,
(byte) 0xaa, (byte) 0xbb, (byte) 0xaa, (byte) 0xb,
(byte) 0xaa, (byte) 0xbb};
final short uv = 0x0100;
final Versionstamp vs = Versionstamp.complete(tv, uv);
// BUG (asserting bug in getUserVersion())
Assert.assertNotEquals(uv, vs.getUserVersion());
Assert.assertEquals(uv, unpackUserVersion(vs.getBytes(), 10));
}
// FIXED
private static int unpackUserVersion(byte[] bytes, int pos) {
return (((int)bytes[pos] & 0xff) << 8) | ((int)bytes[pos + 1] & 0xff);
}