child of #14942
I have read check documentation: https://checkstyle.org/checks/coding/unusedlocalvariable.html#UnusedLocalVariable
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
PS D:\CS\test> cat src/Test.java
import java.io.BufferedReader;
public class Test {
void test() throws Exception {
try (var resource = new BufferedReader(null)) {
}
}
}
PS D:\CS\test> cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<module name="TreeWalker">
<module name="UnusedLocalVariable"/>
</module>
</module>
PS D:\CS\test> java -jar checkstyle-10.17.0-all.jar -c config.xml src/Test.java
Starting audit...
Audit done.
PS D:\CS\test>
Describe what you want in detail.
I suggest to add new property called validateResourceSpecifications to control whether to validate resources. becuase we have no choice but to declare the resource but when it is unused it should be declared as unnamed variable. The fix for this example will be as follow
try (var _ = new BufferedReader(null)) {
}
users under java 21 (including us, we will have a lot of similar violtion due to the non use of resources) can't use unnamed variables. That's why I suggest new property to be able to control this behaviour.
child of #14942
I have read check documentation: https://checkstyle.org/checks/coding/unusedlocalvariable.html#UnusedLocalVariable
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
Describe what you want in detail.
I suggest to add new property called
validateResourceSpecificationsto control whether to validate resources. becuase we have no choice but to declare the resource but when it is unused it should be declared as unnamed variable. The fix for this example will be as followusers under java 21 (including us, we will have a lot of similar violtion due to the non use of resources) can't use unnamed variables. That's why I suggest new property to be able to control this behaviour.