Qube: Community 9.9
If a stream is created and not handled via try-with-resources and the stream is returned, the rule does not hit. That’s correct. But if it is pushed into an external method and a stream is returned by that method (probably to wrap the stream) and this result is returned, the rule produces an issue.
I think, in the described case the rule can safely assume, that the external method does not return a fresh stream and discard the passed in stream or what ever. Hence the issue is a FP.
Example:
public class X {
public static InputStream wrap(InputStream in) {
return new BufferedInputStream(in); // Wrap the passed in stream somehow.
}
}
public InputStream foo() throws IOException {
return X.wrap(new FileInputStream("foo.txt")); // FP
}