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

Handler should implement java.lang.AutoCloseable

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P3 P3
    • None
    • None
    • core-libs

      A DESCRIPTION OF THE REQUEST :
      All classes with a close() method should implement java.lang.AutoCloseable so try-with-resources (TWR) can be used.

      e.g., java.util.logging.Handler has a close() method, yet it does not implement ava.lang.AutoCloseable.

      I know that use cases wherein TWR will be useful for a Handler are limited, but I've actually run into one, and I don't see how a Handler implementing AutoCloseable would actually cause a problem.

      JUSTIFICATION :
      TWR is nice. It should be able to be used in more places.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All classes with a close() method implementing java.lang.AutoCloseable.
      ACTUAL -
      Some classes with a close() method don't implement java.lang.AutoCloseable, e.g., java.util.logging.Handler.

      CUSTOMER SUBMITTED WORKAROUND :
      use try {} finally {} instead of TWR

            dfuchs Daniel Fuchs
            coffeys Sean Coffey
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: