From 9f349385ec29ced175233cb0c3a247b87719cee3 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 26 Apr 2023 16:25:25 +0200 Subject: [PATCH] classlib: fix issue in BitSet.set --- .../src/main/java/org/teavm/classlib/java/util/TBitSet.java | 6 ++++++ .../test/java/org/teavm/classlib/java/util/BitSetTest.java | 3 +++ 2 files changed, 9 insertions(+) diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TBitSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/TBitSet.java index 41202ae44..03076c117 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TBitSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TBitSet.java @@ -169,6 +169,9 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { if (fromIndex > toIndex) { throw new TIndexOutOfBoundsException(); } + if (fromIndex == toIndex) { + return; + } int fromDataIndex = fromIndex / 32; int toDataIndex = toIndex / 32; if (toIndex > length) { @@ -224,6 +227,9 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { return; } toIndex = TMath.min(length, toIndex); + if (fromIndex == toIndex) { + return; + } int fromDataIndex = fromIndex / 32; int toDataIndex = toIndex / 32; if (fromDataIndex == toDataIndex) { diff --git a/tests/src/test/java/org/teavm/classlib/java/util/BitSetTest.java b/tests/src/test/java/org/teavm/classlib/java/util/BitSetTest.java index a2067a29a..87c94ff78 100644 --- a/tests/src/test/java/org/teavm/classlib/java/util/BitSetTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/util/BitSetTest.java @@ -878,6 +878,9 @@ public class BitSetTest { bs.set(2, 2); assertFalse("Bit got set incorrectly ", bs.get(2)); + + bs = new BitSet(); + bs.set(0, 0); } @Test