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

Regression false-positive FinalLocalVariable #3172

Closed
archmageirvine opened this Issue May 13, 2016 · 7 comments

Comments

Projects
None yet
4 participants
@archmageirvine

archmageirvine commented May 13, 2016

The variable s in the following code cannot be made final, yet recent versions of checkstyle claims that it can.

$ java -jar ~/java/cvscheck/lib/checkstyle-6.18-all.jar -c myconfig.xml Bug.java
Starting audit...
[WARN] /home/sean/Bug.java:13:15: Variable 's' should be declared final. [FinalLocalVariable]
Audit done.

import java.util.Arrays;
import java.util.ArrayList;

public final class Bug {

  Bug() { }

  private static boolean f() {
    return Math.random() > 0;
  }

  public static void main(final String[] args) {
    Integer[] s;
    if (f()) {
      s = new Integer[0];
    } else {
      s = new Integer[5];
      if (f()) {
        final ArrayList<Integer> retain = new ArrayList<>();
        for (final Integer c : s) {
          if (f()) {
            retain.add(c);
          }
        }
        s = retain.toArray(new Integer[retain.size()]);
      }
      if (f() && s.length > 0) {
        s = new Integer[] {s[0]};
      }
    }
    System.out.println(Arrays.toString(s));
  }
}

Content of config:

<?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">
    <property name="severity" value="warning"/>
    <module name="TreeWalker">
        <module name="FinalLocalVariable">
            <property name="tokens" value="VARIABLE_DEF,PARAMETER_DEF"/>
        </module>
    </module>
</module>

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani May 13, 2016

Member

Do you know in what checktyle version, there were no violation?

Member

romani commented May 13, 2016

Do you know in what checktyle version, there were no violation?

@romani romani added the approved label May 13, 2016

@archmageirvine

This comment has been minimized.

Show comment
Hide comment
@archmageirvine

archmageirvine May 13, 2016

It was fine in 6.1 (and possibly later).

It was fine in 6.1 (and possibly later).

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach May 13, 2016

Member

6.14 was the first CS version that showed no violations.

Member

rnveach commented May 13, 2016

6.14 was the first CS version that showed no violations.

@rnveach rnveach added the medium label Mar 2, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Mar 14, 2017

Member

@Luolc , can you help us with this issue ?

Member

romani commented Mar 14, 2017

@Luolc , can you help us with this issue ?

@Luolc

This comment has been minimized.

Show comment
Hide comment
@Luolc

Luolc Mar 15, 2017

Contributor

@romani I will look over the related codes and get familiar with this issue. Currently I am focusing on the indentation issue. So I might not be able to solve this immediately.

Contributor

Luolc commented Mar 15, 2017

@romani I will look over the related codes and get familiar with this issue. Currently I am focusing on the indentation issue. So I might not be able to solve this immediately.

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Mar 15, 2017

Member

this is not easy issue , you will not do it immediately for sure.

Member

romani commented Mar 15, 2017

this is not easy issue , you will not do it immediately for sure.

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 19, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 19, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 19, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 19, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 20, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 20, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 20, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 20, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 21, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 21, 2017

Luolc added a commit to Luolc/checkstyle that referenced this issue Mar 23, 2017

romani added a commit that referenced this issue Mar 23, 2017

@romani romani added this to the 7.7 milestone Mar 23, 2017

@romani romani added the bug label Mar 23, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Mar 23, 2017

Member

fix is merged

Member

romani commented Mar 23, 2017

fix is merged

@romani romani closed this Mar 23, 2017

GitToasterhub added a commit to GitToasterhub/checkstyle that referenced this issue Mar 26, 2017

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