Details
-
Bug
-
Resolution: Fixed
-
P2
-
None
-
b108
-
Verified
Description
Specification for the method BaseStream.onClose()
http://download.java.net/lambda/b101/docs/api/java/util/stream/BaseStream.html#onClose(java.lang.Runnable)
gives an impression that method returns not (always) the same stream and handlers are associated each with separate stream in the chain, being aware only of the "parent" handlers in the chain.
While the implementation shows that it doesn't matter which of the streams in the chain is being triggered for closing - all the listeners are notified. Please see the following code:
import java.util.stream.BaseStream;
import java.util.stream.Stream;
public class OnClose {
public static void main(String[] args) {
final Stream s = Stream.empty();
BaseStream c1 = s.onClose(() -> {
System.out.println("handler 1");
});
BaseStream c2 = c1.onClose(() -> {
System.out.println("handler 2");
});
BaseStream c3 = c2.onClose(() -> {
System.out.println("handler 3");
});
// all the handlers will be called
c1.close();
}
}
the output will be:
handler 1
handler 2
handler 3
This looks like either a bug in implementation or behavior not clearly described by the specification.
http://download.java.net/lambda/b101/docs/api/java/util/stream/BaseStream.html#onClose(java.lang.Runnable)
gives an impression that method returns not (always) the same stream and handlers are associated each with separate stream in the chain, being aware only of the "parent" handlers in the chain.
While the implementation shows that it doesn't matter which of the streams in the chain is being triggered for closing - all the listeners are notified. Please see the following code:
import java.util.stream.BaseStream;
import java.util.stream.Stream;
public class OnClose {
public static void main(String[] args) {
final Stream s = Stream.empty();
BaseStream c1 = s.onClose(() -> {
System.out.println("handler 1");
});
BaseStream c2 = c1.onClose(() -> {
System.out.println("handler 2");
});
BaseStream c3 = c2.onClose(() -> {
System.out.println("handler 3");
});
// all the handlers will be called
c1.close();
}
}
the output will be:
handler 1
handler 2
handler 3
This looks like either a bug in implementation or behavior not clearly described by the specification.