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

BitSet.toString() can throw IndexOutOfBoundsException

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7u51
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b13
    • CPU:
      x86_64
    • OS:
      windows_7
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :


        A DESCRIPTION OF THE PROBLEM :
        When set Integer.MAX_VALUE - 1 to BitSet, then call the toString method.
        It will throw exception: java.lang.IndexOutOfBoundsException: fromIndex < 0: -2147483648

        Test code:
            public static void main(String[] args) {
                BitSet bitSet = new BitSet();
                bitSet.set(Integer.MAX_VALUE - 1);
                System.out.println( bitSet.toString());
            }

        The bug was occured at 1189 line of BitSet source.
        for (i = nextSetBit(i+1); i >= 0; i = nextSetBit(i+1)) {

        If set Integer.MAX_VALUE to BitSet, exception will throw at the first nextSetBit(i+1). If set Integer.MAX_VALUE - 1 to BitSet, exception will throw at the second nextSetBit(i+1).

        I think before call nextSetBit(i+1) method, to check i is equal to Integer.MAX_VALUE is better.




        REPRODUCIBILITY :
        This bug can be reproduced always.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                igerasim Ivan Gerasimov
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: