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

java.util.stream.Stream should close closeable spliterator

    XMLWordPrintable

Details

    Description

      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


      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: