From 7947981b4b4d6055ffad4b9430aa6e60ef93f2d0 Mon Sep 17 00:00:00 2001 From: Mike Keesey Date: Fri, 6 Jul 2012 23:33:05 -0600 Subject: [PATCH] Fixed issue where BitSet didn't handle a range of 64 bits correctly on bulk operations - now just return the predefined MASK which has all the bits set when requesting that all the bits be set. --- classpath/java/util/BitSet.java | 6 +++++- test/BitsetTest.java | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/classpath/java/util/BitSet.java b/classpath/java/util/BitSet.java index 8728f23f5c..d27dd05c3c 100644 --- a/classpath/java/util/BitSet.java +++ b/classpath/java/util/BitSet.java @@ -34,7 +34,11 @@ public class BitSet implements Serializable, Cloneable { private static long getTrueMask(int fromIndex, int toIndex) { int currentRange = toIndex - fromIndex; - return (((1L << currentRange) - 1L) << (fromIndex % BITS_PER_LONG)); + if (currentRange == 64) { + return MASK; + } else { + return (((1L << currentRange) - 1L) << (fromIndex % BITS_PER_LONG)); + } } public BitSet(int bitLength) { diff --git a/test/BitsetTest.java b/test/BitsetTest.java index 23d222ee26..6609eb60dd 100644 --- a/test/BitsetTest.java +++ b/test/BitsetTest.java @@ -96,6 +96,13 @@ public class BitsetTest { assertTrue("bit 2 should be 0", !bitset.get(2)); assertTrue("bit 3 should be 1", bitset.get(3)); assertCardinality(bitset, 17); + + bitset = new BitSet(70); + bitset.flip(0, 65); + for (int i=0; i < 65; ++i) { + assertTrue("bit " + i + " should be set", bitset.get(i)); + } + assertTrue("bit 65 should not be set", !bitset.get(65)); } static void assertTrue(String msg, boolean flag) {