8076442: Cannot fully read BitSet.stream() if bit Integer.MAX_VALUE is set

Reviewed-by: alanb, henryjen
This commit is contained in:
Chris Hegarty 2015-04-07 10:33:08 +01:00
parent 2de64493a2
commit 7e6f12e6e9
2 changed files with 5 additions and 2 deletions

View File

@ -1229,7 +1229,7 @@ public class BitSet implements Cloneable, java.io.Serializable {
public int nextInt() {
if (next != -1) {
int ret = next;
next = nextSetBit(next+1);
next = (next == Integer.MAX_VALUE) ? -1 : nextSetBit(next+1);
return ret;
} else {
throw new NoSuchElementException();

View File

@ -43,7 +43,7 @@ import static org.testng.Assert.fail;
/**
* @test
* @summary test BitSet stream
* @bug 8012645
* @bug 8012645 8076442
* @run testng BitSetStreamTest
*/
public class BitSetStreamTest {
@ -70,6 +70,7 @@ public class BitSetStreamTest {
{ "step 5", IntStream.range(0, 255).map(f -> f * 5) },
{ "step 7", IntStream.range(0, 255).map(f -> f * 7) },
{ "1, 10, 100, 1000", IntStream.of(1, 10, 100, 1000) },
{ "max int", IntStream.of(Integer.MAX_VALUE) },
{ "25 fibs", IntStream.generate(new Fibs()).limit(25) }
};
@ -106,6 +107,8 @@ public class BitSetStreamTest {
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
assertTrue(it.hasNext());
assertEquals(it.nextInt(), i);
if (i == Integer.MAX_VALUE)
break; // or (i+1) would overflow
}
assertFalse(it.hasNext());
}