-
Bug
-
Resolution: Fixed
-
P4
-
8-repo-lambda
-
b108
-
Verified
If some/all stream close handlers for some reason share the same instance of exception which they throw the resulting exception would not contain the full list of the suppressed (same) instances.
Please see the following code sample:
import java.util.Arrays;
import java.util.stream.Stream;
public class OnCloseSuppressed {
public static void main(String[] args) {
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
RuntimeException exception = new RuntimeException();
stream.onClose(() -> {throw exception;});
stream.onClose(() -> {throw exception;});
stream.onClose(() -> {throw exception;});
try {
stream.close();
} catch (Exception e) {
System.out.println("e = " + e);
System.out.println("e.getSuppressed() = " + Arrays.toString(e.getSuppressed()));
}
}
}
For JDK8b102-lambda the output will be:
e = java.lang.RuntimeException
e.getSuppressed() = []
Though such scenario of exception instance sharing doesn't seem common this case looks like deserving to be handled like any other, currently it appears to be contradicting the spec, Or the spec needs to reflect current behavior more clearly.
Please see the following code sample:
import java.util.Arrays;
import java.util.stream.Stream;
public class OnCloseSuppressed {
public static void main(String[] args) {
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
RuntimeException exception = new RuntimeException();
stream.onClose(() -> {throw exception;});
stream.onClose(() -> {throw exception;});
stream.onClose(() -> {throw exception;});
try {
stream.close();
} catch (Exception e) {
System.out.println("e = " + e);
System.out.println("e.getSuppressed() = " + Arrays.toString(e.getSuppressed()));
}
}
}
For JDK8b102-lambda the output will be:
e = java.lang.RuntimeException
e.getSuppressed() = []
Though such scenario of exception instance sharing doesn't seem common this case looks like deserving to be handled like any other, currently it appears to be contradicting the spec, Or the spec needs to reflect current behavior more clearly.