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

BitSet.get(int, int) always returns the empty BitSet when the Integer.MAX VALUE is set

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • core-libs
    • None
    • behavioral
    • low
    • Hide
      Existing users who could set this bit would likely have already encounterd the bug with get(int,int) and length().

      The change in valueOf(...)'s specifcation already reflects the functionality of the methods, the only change is that it now also applies to the bit at Integer.MAX_VALUE.
      Show
      Existing users who could set this bit would likely have already encounterd the bug with get(int,int) and length(). The change in valueOf(...)'s specifcation already reflects the functionality of the methods, the only change is that it now also applies to the bit at Integer.MAX_VALUE.
    • Java API
    • SE

      Summary

      Reject interactions with the bit at position Integer.MAX_VALUE in BitSet. This solves issues relating to the overflow of length(), as well as inconsistencies between 1 and 2 parameter versions of the methods set, clear, flip and get.

      Problem

      BitSet.length() returns a negative value when Integer.MAX_VALUE is set, such as by using the set(int) method or by passing large arrays to a BitSet constructor. This also causes the get(fromIndex, toIndex) method to always return the empty BitSet when passed with valid parameters, regardless of the value of fromIndex and toIndex.

      Furthermore, there is a discrepancy between bits that are accessible in a method such as set(int) and a method such as set(int,int). In the second method, because the method goes up to BUT NOT INCLUDING toIndex, it can never access the Integer.MAX_VALUE bit, while the first method can.

      Solution

      Prevent accessing the Integer.MAX_VALUE bit, such as by throwing an exception if methods try to access Integer.MAX_VALUE, such as in set(Integer.MAX_VALUE). For the methods that take in arrays and return a BitSet such as valueOf(longs[] longs), these should specifically check and set the Integer.MAX_VALUE bit to 0 to avoid length() overflowing when wordsInUse refers to the word that contains the Integer.MAX_VALUE bit.

      length() returns a non-negative number.

      In the methods set(int bitIndex), set(int bitIndex, int value), clear(int bitIndex), flip(int bitIndex) and get(int bitIndex), bitIndex must be smaller than Integer.MAX_VALUE. If Integer.MAX_VALUE is used, a IndexOutOfRangeException should be raised.

      valueOf(...) ignores bits from bitIndex Integer.MAX_VALUE onwards (inclusive).

      Specification

      // TODO

            smarks Stuart Marks
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: