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

UncaughtExceptionHandler for Cleaner

XMLWordPrintable

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

      The specification for the Cleaner class states that, "All exceptions thrown by the cleaning action are ignored."

      This matches the behavior of finalizer, the now-deprecated mechanism for GC-triggered cleanup that Cleaner can be used in place of.

      However, this situation leaves the developer uninformed about problems that occur during resource cleanup,including potential resource leaks.

      With Cleaner, we can do better.

      The current API allows a Cleaner to be created with a user-supplied ThreadFactory. This thread factory can set an UncaughtExceptionHandler on the thread(s) it creates. However the Cleaner spec mandates that exceptions thrown in the cleaning action are ignored. The spec could be updated to allow exceptions to be delivered to such an UncaughtExceptionHandler.

      We might also consider adding a method directly on Cleaner to allow a user to set an UncaughtExceptionHandler to receive exception thrown by the Cleaning Actions run on the Cleaner.

            bchristi Brent Christian
            bchristi Brent Christian
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: