Java Bindings - Bug in VersionStamp.getUserVersion()

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);
    }

This sounds like it would be a perfectly good GitHub issue. If you also have a patch you’d want to contribute to fix it, that also sounds reasonable. I think we would probably want this against the release-6.0 branch (instead of the master branch). I guess I could see the argument that it should be against the release-5.2 branch. But definitely one of the release branches.

Sure. I will submit the patch against 6.0 branch by tomorrow.

Hm, so, we’re cutting a new patch release of 6.0 branch today. Given that this fix is relatively quick, I think I’ll go ahead and do it now.

Sure. Please go ahead.

Here’s the issue, if you’re so interested: https://github.com/apple/foundationdb/issues/761

The PR is linked within