You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/var/tmp $ javac Test1.java
/var/tmp $ cat config.xml
<?xml version="1.0"?><!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN""https://checkstyle.org/dtds/configuration_1_3.dtd"><module name = "Checker"><module name="TreeWalker"><module name="VariableDeclarationUsageDistance"><property name="validateBetweenScopes" value="true"/><property name="allowedDistance" value="1"/></module></module></module>
/var/tmp $ cat Test1.java
import java.util.Iterator;
public class Test1 {
public void method(){
int a=1;
class GeneralLogic {
public <T> Iterator<T> method(T[] b) throws Exception{
if(a>0){
System.out.println(b.length);
}
return null;
}
}
}
}
/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-10.9.3-all.jar -c config.xml Test1.java
Starting audit...
[WARN] /var/tmp/Test.java:5:9: Distance between variable 'a' declaration and its first usage is 3,
but allowed 1. Consider making that variable final if you still need to store its value in
advance (before method calls that might have side effects on the original value).
[VariableDeclarationUsageDistance]
Audit done.
The distance should be 1. This three were caused by generic type which is <T>, parameter type in the method signature and throws. I think the correct distance one should be caused by the expression in the if condition.
Activity
Issue checkstyle#13038: add Literal_throws to skip
Issue checkstyle#13038: add Literal_throws to skip
Issue checkstyle#13038: add Literal_throws to skip
Issue checkstyle#13038: Add token type parameter to isZeroDistanceTok…
Issue checkstyle#13038: Add token type parameter to isZeroDistanceTok…
Issue checkstyle#13038: Add case for class and method def in calculat…
Issue checkstyle#13038: Modifed testGenralClass4 to eliminate violation
romani commentedon Nov 11, 2023
almost done update is at #13065 , everyone in web is welcome to reuse and finish
jxr98 commentedon Feb 29, 2024
I'm on it. Will try to solve it within this week. Thanks. 😃
19 remaining items
Issue checkstyle#13038: handled inner class method definition in Vari…
Issue checkstyle#13038: handled inner class method definition in Vari…
Issue checkstyle#13038: handled inner class method definition in Vari…
Issue checkstyle#13038: handled inner class method definition in Vari…
Issue checkstyle#13038: handled inner class method definition in Vari…
romani commentedon Oct 17, 2025
There is some incomplete update at #17526 that can be reuses.
Everyone is welcome to send PR
vivek-0509 commentedon Jan 14, 2026
I am on it
Issue checkstyle#13038: Fix incorrect distance calculation for method…
Issue #13038: Fix incorrect distance calculation for method definitions
romani commentedon Jan 25, 2026
fix is merged