classlib: fix issue in BitSet.set

This commit is contained in:
Alexey Andreev 2023-04-26 16:25:25 +02:00
parent 7cd121ec97
commit 9f349385ec
2 changed files with 9 additions and 0 deletions

View File

@ -169,6 +169,9 @@ public class TBitSet extends TObject implements TCloneable, TSerializable {
if (fromIndex > toIndex) { if (fromIndex > toIndex) {
throw new TIndexOutOfBoundsException(); throw new TIndexOutOfBoundsException();
} }
if (fromIndex == toIndex) {
return;
}
int fromDataIndex = fromIndex / 32; int fromDataIndex = fromIndex / 32;
int toDataIndex = toIndex / 32; int toDataIndex = toIndex / 32;
if (toIndex > length) { if (toIndex > length) {
@ -224,6 +227,9 @@ public class TBitSet extends TObject implements TCloneable, TSerializable {
return; return;
} }
toIndex = TMath.min(length, toIndex); toIndex = TMath.min(length, toIndex);
if (fromIndex == toIndex) {
return;
}
int fromDataIndex = fromIndex / 32; int fromDataIndex = fromIndex / 32;
int toDataIndex = toIndex / 32; int toDataIndex = toIndex / 32;
if (fromDataIndex == toDataIndex) { if (fromDataIndex == toDataIndex) {

View File

@ -878,6 +878,9 @@ public class BitSetTest {
bs.set(2, 2); bs.set(2, 2);
assertFalse("Bit got set incorrectly ", bs.get(2)); assertFalse("Bit got set incorrectly ", bs.get(2));
bs = new BitSet();
bs.set(0, 0);
} }
@Test @Test