Fixing BitArrayBin to not overflow in certain cases with numbers larger
than Int max

(cherry picked from commit 09456480b8)
This commit is contained in:
Christopher L. Shannon (cshannon) 2016-09-23 14:30:37 -04:00
parent e0c70b843f
commit bf7a19eead
2 changed files with 11 additions and 1 deletions

View File

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

View File

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