FULL PRODUCT VERSION :
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 4.2.0-42-generic #49-Ubuntu SMP Tue Jun 28 21:26:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
If a BitSet contains the bit Integer.MAX_VALUE, the stream iterator throws an IndexOutOfBoundsException exception after visiting this bit
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
use a stream iterator on a bitset with bit Integer.MAX_VALUE set and call the stream iterator
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the iterator should not throw any exception at all
ACTUAL -
the iterator throws an IndexOutOfBoundsException
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IndexOutOfBoundsException: fromIndex < 0: -2147483648
at java.util.BitSet.nextSetBit(BitSet.java:712)
at java.util.BitSet$1BitSetIterator.nextInt(BitSet.java:1232)
at java.util.PrimitiveIterator$OfInt.forEachRemaining(PrimitiveIterator.java:115)
at java.util.Spliterators$IntIteratorSpliterator.forEachRemaining(Spliterators.java:1908)
at java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:557)
at me.pg.GeneratedRegressionTest.testBitSet(GeneratedRegressionTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.BitSet;
import org.junit.Test;
public class BitSetTest {
@Test
public void testStreamIteratorNext() {
BitSet bs = new BitSet(Integer.MAX_VALUE);
bs.set(Integer.MAX_VALUE);
bs.stream().iterator().next();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Test if a given BitSet contains the bit Integer.MAX_VALUE. eg:
if (Integer.MAX_VALUE == bs.length()) {
bs.clear(Integer.MAX_VALUE);
bs.stream().forEach(lambda);
lambda.accept(Integer.MAX_VALUE);
bs.set(Integer.MAX_VALUE);
} else {
bs.stream().forEach(lambda);
}
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 4.2.0-42-generic #49-Ubuntu SMP Tue Jun 28 21:26:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
If a BitSet contains the bit Integer.MAX_VALUE, the stream iterator throws an IndexOutOfBoundsException exception after visiting this bit
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
use a stream iterator on a bitset with bit Integer.MAX_VALUE set and call the stream iterator
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the iterator should not throw any exception at all
ACTUAL -
the iterator throws an IndexOutOfBoundsException
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IndexOutOfBoundsException: fromIndex < 0: -2147483648
at java.util.BitSet.nextSetBit(BitSet.java:712)
at java.util.BitSet$1BitSetIterator.nextInt(BitSet.java:1232)
at java.util.PrimitiveIterator$OfInt.forEachRemaining(PrimitiveIterator.java:115)
at java.util.Spliterators$IntIteratorSpliterator.forEachRemaining(Spliterators.java:1908)
at java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:557)
at me.pg.GeneratedRegressionTest.testBitSet(GeneratedRegressionTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.BitSet;
import org.junit.Test;
public class BitSetTest {
@Test
public void testStreamIteratorNext() {
BitSet bs = new BitSet(Integer.MAX_VALUE);
bs.set(Integer.MAX_VALUE);
bs.stream().iterator().next();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Test if a given BitSet contains the bit Integer.MAX_VALUE. eg:
if (Integer.MAX_VALUE == bs.length()) {
bs.clear(Integer.MAX_VALUE);
bs.stream().forEach(lambda);
lambda.accept(Integer.MAX_VALUE);
bs.set(Integer.MAX_VALUE);
} else {
bs.stream().forEach(lambda);
}
- duplicates
-
JDK-8076442 Cannot fully read BitSet.stream() if bit Integer.MAX_VALUE is set
-
- Closed
-