Affects PMD Version: 6.16.0
Rule: CloseResource
Description:
If a IO stream is passed into a method as a method parameter and then assigned to a local variable, the rule should not be triggered. In that case, the stream has not be created locally, so the caller of the method is responsible to close it.
Code Sample demonstrating the issue:
import java.io.*; public class CloseResourceFP { public void check(InputStream in) { if (in instanceof FileInputStream) { FileInputStream fin = (FileInputStream) in; doCheck(fin); } else if (in instanceof ByteArrayInputStream) { ByteArrayInputStream bin = (ByteArrayInputSream) in; doCheck(bin); } else { BufferedInputStream buf = new BufferedInputStream(in); doCheck(buf); } } public void dump(final Writer writer) { final PrintWriter printWriter = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer); printWriter.println(this); } }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4