-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
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.
"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.