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

Add @SafeResource for methods that return AutoCloseable to avoid warnings

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      "Potential resource leak" warnings are generally very useful. However for methods that return an AutoCloseable type, where the caller just wants a reference, and is not expected to manage the resource lifecycle - i.e. call close(), this warning is an annoyance. It requires littering the code with @SuppressWarnings("resource"), or turning off the warning. Similar in intent to @SafeVarargs, an annotation @SafeResource on the method would mean the reference returned to the caller does not generate "Potential resource leak" warnings. An example would be java.net.Socket.getInputStream() - it is not required to close the stream each time it is called, calling Socket.close() should suffice.


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

              Created:
              Updated: