Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6222207

BitSet internal invariants may be violated

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 6
    • 6
    • core-libs
    • None
    • b25
    • generic
    • generic
    • Verified

      BitSet.java has some invariants, which can be understood best using
      this java code:

          private void checkInvariants() {
      assert(wordsInUse == 0 || words[wordsInUse - 1] != 0);
      assert(wordsInUse >= 0 && wordsInUse <= words.length);
      assert(wordsInUse == words.length || words[wordsInUse] == 0);
          }

      But these invariants do not always hold, leading to corrupt internal
      data corruption and incorrect results.

      One manifestation is this program:
      -------------------------------------------------------------------
      import java.util.*;

      public class Bug {
          public static void main(String[] args) throws Exception {
      BitSet s = new BitSet();
      s.set(127,127);
      System.out.printf("length=%d isEmpty=%b%n", s.length(), s.isEmpty());
          }
      }
      -------------------------------------------------------------------
      Giving:
      length=64 isEmpty=false
      when correct is:
      length=0 isEmpty=true

      ###@###.### 2005-1-27 06:57:58 GMT
      ###@###.### 2005-1-27 07:01:50 GMT

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: