-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
The class java.util.stream.StreamSupport allows creation of a java.util.stream.Stream object based on an object implementing the java.util.Spliterator interface. See method: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/StreamSupport.html#stream(java.util.Spliterator,boolean)
The first parameter of the abovementioned method is a spliterator object. As this is passed to a created Stream object, it creates a relation: the created Stream object uses spliterator and it should be responsible for closing the resource if this spliterator implements java.lang.AutoCloseable interface.
Please note that java.util.stream.Stream interface extends java.lang.AutoCloseable so it cooperates nicely with try-with-resources. It would be very convenient to have the method close() of a Stream owning a spliterator to:
- check if the spliterator is instance of java.lang.AutoCloseable,
- if so, cast it to java.lang.AutoCloseable and invoke its close() method.
Related issues:
1) https://bugs.openjdk.org/browse/JDK-8274994
2) https://bugs.openjdk.org/browse/JDK-8151408
The class java.util.stream.StreamSupport allows creation of a java.util.stream.Stream object based on an object implementing the java.util.Spliterator interface. See method: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/StreamSupport.html#stream(java.util.Spliterator,boolean)
The first parameter of the abovementioned method is a spliterator object. As this is passed to a created Stream object, it creates a relation: the created Stream object uses spliterator and it should be responsible for closing the resource if this spliterator implements java.lang.AutoCloseable interface.
Please note that java.util.stream.Stream interface extends java.lang.AutoCloseable so it cooperates nicely with try-with-resources. It would be very convenient to have the method close() of a Stream owning a spliterator to:
- check if the spliterator is instance of java.lang.AutoCloseable,
- if so, cast it to java.lang.AutoCloseable and invoke its close() method.
Related issues:
1) https://bugs.openjdk.org/browse/JDK-8274994
2) https://bugs.openjdk.org/browse/JDK-8151408
- relates to
-
JDK-8151408 add a stream factory method that can produce a finite stream
- Open
-
JDK-8274994 Add a method to Stream API to consume and close the stream without using try-with-resources
- Draft