src/share/classes/java/util/stream/IntPipeline.java

Print this page
rev 7982 : 8017513: Support for closeable streams
8022237: j.u.s.BaseStream.onClose() has an issue in implementation or requires spec clarification
8022572: Same exception instances thrown from j.u.stream.Stream.onClose() handlers are not listed as suppressed
Summary: BaseStream implements AutoCloseable; Remove CloseableStream and DelegatingStream
Reviewed-by: alanb, mduigou, psandoz
Contributed-by: brian.goetz@oracle.com

@@ -300,15 +300,16 @@
                         downstream.begin(-1);
                     }
 
                     @Override
                     public void accept(int t) {
+                        try (IntStream result = mapper.apply(t)) {
                         // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
-                        IntStream result = mapper.apply(t);
                         if (result != null)
                             result.sequential().forEach(i -> downstream.accept(i));
                     }
+                    }
                 };
             }
         };
     }