Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8022572

Same exception instances thrown from j.u.stream.Stream.onClose() handlers are not listed as suppressed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 8-repo-lambda
    • core-libs

    Description

      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.


      Attachments

        Activity

          People

            henryjen Henry Jen
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: