I have a class called JavaShellStream that extends the interfaces Closeable and Autocloseable. However, when I use the class, and do not call its close() method, no warning is triggered that there is a resource leak. I have another class called JavaShell which has a method called exec(String cmd) that returns a JavaShellStream object. When I create a new JavaShellStream object in the following way, no resource leak warning is triggered:
//workingDir is a File object that sets the working directory
JavaShell js = new JavaShell(workingDir);
//execute the "ls" command and retrieve output as a JavaShellStream
JavaShellStream jss = js.exec("ls");
/*
* some code to read the text from the stream
* but DOES NOT close the stream
*/
// Note that I am NOT calling the close() method
Why is no warning triggered here that there is a resource leak because the JavaShellStream jss is never closed? The answer from here says that all that's required to trigger it is to implement the interface Closeable, but my class implements both Closeable and Autocloseable but will not trigger any warning when unclosed.