/tmp/checkstyle.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="FinalLocalVariable">
<property name="tokens" value="VARIABLE_DEF,PARAMETER_DEF"/>
</module>
</module>
</module>
/tmp/Test.java
public class Test
{
public void method()
{
final java.util.List<Object> list = new java.util.ArrayList<>();
for ( int i = 0, s0 = list.size(); i < s0; i++ )
{
}
}
}
Invocation
java -Duser.language=en -cp checkstyle-5.7-all.jar com.puppycrawl.tools.checkstyle.Main -c /tmp/checkstyle.xml /tmp/Test.java
Report
Starting audit...
/tmp/Test.java:12:26: Variable 's0' should be declared final.
Audit done.
There is no way to declare variable 's0' final other than moving it out of the 'for' loop scope.