diff --git a/activemq-client/src/main/java/org/apache/activemq/util/BitArrayBin.java b/activemq-client/src/main/java/org/apache/activemq/util/BitArrayBin.java index d988ae1830..e19b8174bc 100755 --- a/activemq-client/src/main/java/org/apache/activemq/util/BitArrayBin.java +++ b/activemq-client/src/main/java/org/apache/activemq/util/BitArrayBin.java @@ -144,7 +144,7 @@ public class BitArrayBin implements Serializable { private int getBin(long index) { int answer = 0; if (longFirstIndex < 0) { - longFirstIndex = (int) (index - (index % BitArray.LONG_SIZE)); + longFirstIndex = (index - (index % BitArray.LONG_SIZE)); } else if (longFirstIndex >= 0) { answer = (int)((index - longFirstIndex) / BitArray.LONG_SIZE); } diff --git a/activemq-client/src/test/java/org/apache/activemq/util/BitArrayBinTest.java b/activemq-client/src/test/java/org/apache/activemq/util/BitArrayBinTest.java index 2b17d8fd60..07e653d12f 100644 --- a/activemq-client/src/test/java/org/apache/activemq/util/BitArrayBinTest.java +++ b/activemq-client/src/test/java/org/apache/activemq/util/BitArrayBinTest.java @@ -171,4 +171,14 @@ public class BitArrayBinTest { toTest.setBit(largeNum, true); assertTrue("set", toTest.getBit(largeNum)); } + + //This test is slightly different in that it doesn't set bit 1 to + //true as above which was causing a different result before AMQ-6431 + @Test + public void testLargeNumber2() { + BitArrayBin toTest = new BitArrayBin(1024); + long largeNum = Integer.MAX_VALUE * 2L + 100L; + toTest.setBit(largeNum, true); + assertTrue(toTest.getBit(largeNum)); + } }