A resource of try-with-resources is also closed by hand inside the block
What it finds
A resource declared in the head of a try is closed when the block ends. A call of close() on it inside the block closes it a second time, and code after the call in the block works with a closed resource.
Reported is close() on a resource variable of the try it is in.
From the rule's source, close_in_resource_block.rs.
import java.io.FileInputStream; class Reader2 { void read(String path) throws Exception { try (FileInputStream in = new FileInputStream(path)) { in.read(); in.close();tx0 reports: closing it here is redundant } }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:close-in-resource-block" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:close-in-resource-block] reason="..."tx0 explain tx0/java:close-in-resource-block shows the same in the terminal. Found a false positive? Report it.