New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FinalLocalVariable: false positive when variable is assigned inside and outside switch-block #3074

Closed
MEZk opened this Issue Apr 1, 2016 · 0 comments

Comments

Projects
None yet
2 participants
@MEZk
Contributor

MEZk commented Apr 1, 2016

Configuration:

<?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="FinalLocalVariable" />
    </module>
</module>

Input:

public class Test {
private static void combine(final int[][] m, final int x, final int y, final int d, final int[] regionSizes) {
    final int a = m[y][x] & 1;
    int b;
    switch (d) {
    case 1:
      b = m[y - 1][x];
      break;
    case 2:
      b = m[y][x - 1];
      break;
    case 3:
      b = m[y][x + 1];
      break;
    default: 
      b = m[y + 1][x];
      break;
    }
    b &= 5;
  }
}

Output:

Starting audit...
[ERROR] /home/andreiselkin/Downloads/Test.java:5:9: Variable 'b' should be declared final. [FinalLocalVariable]
Audit done.
Checkstyle ends with 1 errors.

Variable b cannot be declared final, due to compile time error.

MEZk added a commit to MEZk/checkstyle that referenced this issue Jul 22, 2016

Issue #3074: Fix FinalLocalVariable false positive when variable is a…
…ssigned inside and outside switch-block

@romani romani closed this in #3366 Jul 23, 2016

romani added a commit that referenced this issue Jul 23, 2016

Issue #3074: Fix FinalLocalVariable false positive when variable is a…
…ssigned inside and outside switch-block (#3366)

@romani romani added this to the 7.1 milestone Jul 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment