#671 Variable XYZ should be declared final with for statements.

release_1.0
closed
nobody
None
5
2014-08-21
2012-02-12
No

Having a for loop like

for ( int i = 0, s0 = max; i < max; i++ )

checkstyle outputs

Variable 's0' should be declared final.

This message is wrong, since it is impossible to add a 'final' modifier to that variable.

Discussion

  • Roman Ivanov
    Roman Ivanov
    2013-10-26

    • status: open --> closed
    • Group: --> release_1.0
     
  • Roman Ivanov
    Roman Ivanov
    2013-10-26

    Check is right, No complains in following code.
    final int max =6;
    for (int i = 0, so = max; i < max; i++) {
    so++;
    System.out.println(so);
    }

    Please provide more exact example of problem, post issue in github
    https://github.com/checkstyle/checkstyle/issues with wide description and exact code and exact configuration.

     
    • Please see

      http://www.jomc.org/jomc/1.7/jomc-model-1.7/checkstyle.html

      providing various examples of the issue. Search that site for

      Variable 's0' should be declared final.

      violation messages and take a look at the code producing this violation.

       
  • Please see

    http://www.jomc.org/jomc/1.7/jomc-model-1.7/checkstyle.html

    providing various examples of the issue. Search that site for

    Variable 's0' should be declared final.

    violation messages and take a look at the code producing this violation.