-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
11, 17, 18
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Related issue : https://bugs.openjdk.java.net/browse/JDK-8042355
A similar report was raised in the issue linked above but it still seems to be happening when a call to concat() is introduced in the pipeline.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
'peek' is called only once, i.e, output should be,
PEEK: a
result a
ACTUAL -
'peek' is called for all elements. i'e, output is,
PEEK: a
PEEK: ab
PEEK: abc
PEEK: abcd
result a
---------- BEGIN SOURCE ----------
public class Blah
{
public static void main(String[] args)
{
Stream<String> stream = Stream.of("a", "ab", "abc", "abcd")
// .sorted() // uncommenting this cause 'peek' to be called on all elements
.peek(s -> System.out.println("PEEK: " + s));
// Stream<String> finalStream = stream;
Stream<String> finalStream = Stream.concat(stream, Stream.of());
String result = finalStream.findFirst().orElseThrow();
System.out.println("result " + result);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
collect the sorted result into a list and start a new pipeline
Related issue : https://bugs.openjdk.java.net/browse/JDK-8042355
A similar report was raised in the issue linked above but it still seems to be happening when a call to concat() is introduced in the pipeline.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
'peek' is called only once, i.e, output should be,
PEEK: a
result a
ACTUAL -
'peek' is called for all elements. i'e, output is,
PEEK: a
PEEK: ab
PEEK: abc
PEEK: abcd
result a
---------- BEGIN SOURCE ----------
public class Blah
{
public static void main(String[] args)
{
Stream<String> stream = Stream.of("a", "ab", "abc", "abcd")
// .sorted() // uncommenting this cause 'peek' to be called on all elements
.peek(s -> System.out.println("PEEK: " + s));
// Stream<String> finalStream = stream;
Stream<String> finalStream = Stream.concat(stream, Stream.of());
String result = finalStream.findFirst().orElseThrow();
System.out.println("result " + result);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
collect the sorted result into a list and start a new pipeline
- relates to
-
JDK-8042355 stream with sorted() causes downstream ops not to be lazy
-
- Resolved
-