-
Bug
-
Resolution: Fixed
-
P2
-
17
-
b24
-
b26
java.util.PrimitiveIterator::void forEachRemaining specification says:
> Performs the given action for each remaining element, in the order elements occur when iterating, until all elements have been processed or the action throws an exception
https://download.java.net/java/early_access/jdk17/docs/api/java.base/java/util/PrimitiveIterator.OfInt.html#forEachRemaining(java.util.function.IntConsumer)
Code sample
===========================
import java.util.PrimitiveIterator;
import java.util.stream.IntStream;
public class Test {
public static void main(String... args) {
PrimitiveIterator.OfInt iterator = IntStream.range(1, 5).iterator();
try { iterator.forEachRemaining(
(int i) -> { if (i < 3) System.err.println(i); else throw new RuntimeException("Stop!"); });
} catch (Exception e) {
System.err.println(e);
}
System.out.println("iterator.nextInt() = " + iterator.nextInt());
}
}
===========================
Checking JDK17b23:
> /17/23/jdk-17/bin/javac Test.java
> /17/23/jdk-17/bin/java Test
1
2
java.lang.RuntimeException: Stop!
iterator.nextInt() = 4
Checking JDK17b24:
> /17/24/jdk-17/bin/javac Test.java
> /17/24/jdk-17/bin/java Test
1
2
java.lang.RuntimeException: Stop!
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Spliterators$2Adapter.nextInt(Spliterators.java:747)
at Test.main(Test.java:12)
> Performs the given action for each remaining element, in the order elements occur when iterating, until all elements have been processed or the action throws an exception
https://download.java.net/java/early_access/jdk17/docs/api/java.base/java/util/PrimitiveIterator.OfInt.html#forEachRemaining(java.util.function.IntConsumer)
Code sample
===========================
import java.util.PrimitiveIterator;
import java.util.stream.IntStream;
public class Test {
public static void main(String... args) {
PrimitiveIterator.OfInt iterator = IntStream.range(1, 5).iterator();
try { iterator.forEachRemaining(
(int i) -> { if (i < 3) System.err.println(i); else throw new RuntimeException("Stop!"); });
} catch (Exception e) {
System.err.println(e);
}
System.out.println("iterator.nextInt() = " + iterator.nextInt());
}
}
===========================
Checking JDK17b23:
> /17/23/jdk-17/bin/javac Test.java
> /17/23/jdk-17/bin/java Test
1
2
java.lang.RuntimeException: Stop!
iterator.nextInt() = 4
Checking JDK17b24:
> /17/24/jdk-17/bin/javac Test.java
> /17/24/jdk-17/bin/java Test
1
2
java.lang.RuntimeException: Stop!
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Spliterators$2Adapter.nextInt(Spliterators.java:747)
at Test.main(Test.java:12)
- csr for
-
JDK-8268079 Clarify the specification of iterator and spliterator forEachRemaining
- Closed
- duplicates
-
JDK-8267949 Clarifiy the specification of PrimitiveIterator.forEachRemaining
- Closed