#1128 CompareObjectsWithEquals False Positive comparing boolean (primitive) values

PMD-5.2.2
closed
PMD
4-Minor
Bug
Eclipse PMD plugin 4.0.1-v20130811-0001
2014-12-03
2013-09-04
No

Using Eclipse PMD plugin 4.0.1-v20130811-0001 and this also happens in Sonar v.3.5.

There is a particular situation in which CompareObjectsWithEquals violation is showing when it shouldn't. To show this I have done some dummy classes that show this clearly.

public class SomeClass {
    protected SomeObject object;
}

public class SomeObject {

    private boolean configuration;

    public SomeObject() {
        super();
    }

    public boolean isConfigurationEnabled() {
        return configuration;
    }

    public void setConfiguration(boolean configuration) {
        this.configuration = configuration;
    }
}

public class SonOfSomeClass extends SomeClass {

    protected javax.swing.JCheckBox checkBox;

    public class SomeEmbeddedClass {

        public boolean someNotWorkingMethod(boolean valid){
                // This line presents a CompareObjectsWithEquals violation
            valid |= SonOfSomeClass.this.object.isConfigurationEnabled() != SonOfSomeClass.this.checkBox.isSelected();
            return valid;
        }

        public boolean someWorkingMethod(boolean valid){
                // This line does not present any violation
            valid |= (SonOfSomeClass.this.object.isConfigurationEnabled()) != SonOfSomeClass.this.checkBox.isSelected();
            return valid;
        }
    }
}

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-11-27
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next
     
  • Andreas Dangel

    Andreas Dangel - 2014-11-27

    Will be fixed with the next version (5.2.2).

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks