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

BitSet.toString() can throw IndexOutOfBoundsException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 7u51
    • core-libs
    • b13
    • x86_64
    • windows_7
    • 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

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

                Dates

                  Created:
                  Updated:
                  Resolved: