Menu

#1008 pmd-5.0.0: ImmutableField false positive on self-inc/dec

PMD-5.0.1
closed
pmd (543)
5
2014-07-22
2012-05-13
Anonymous
No

Hi, I'm seeing PDM 5.0.0 reporting the following:

pmd_inc.java:2 Private field 'test' could be made final; it is only initialized in the declaration or constructor.

about the following test case:

public class pmd_inc {
private int test;

public pmd_inc() {
    this.test = 2;
}

public int get_test() {
    return this.test;
}

public void inc_test(int val) {
    this.test += val;
}

}

It seems as if PMD doesn't recognize that "test" is in fact mutable through the += operator and wrongly suggest marking it as final.

Discussion

  • Andreas Dangel

    Andreas Dangel - 2012-06-01

    Thank you for the bug report. It will be fixed for PMD 5.1.

     
  • Andreas Dangel

    Andreas Dangel - 2012-11-23
    • Milestone: PMD-5.1.x --> PMD-5.0.1
     

Log in to post a comment.