mirror of https://github.com/apache/activemq.git
Fixing BitArrayBin to not overflow in certain cases with numbers larger
than Int max
(cherry picked from commit 09456480b8
)
This commit is contained in:
parent
e0c70b843f
commit
bf7a19eead
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue