Menu

#1497 [java] CompareObjectsWithEquals: == ok for enums

New Tickets
not-reproducible
nobody
PMD
3-Major
Bug
CompareObjectsWithEquals
2017-02-06
2016-06-23
rei3ner
No

Rule: CompareObjectsWithEquals

I think, comparison with == and != is ok e.g. for enums.
Could one modify this rule accordingly?

Discussion

  • Andreas Dangel

    Andreas Dangel - 2016-06-25
    • Milestone: PMD-5.5.0 --> New Tickets
     
  • Andreas Dangel

    Andreas Dangel - 2016-08-12
    • labels: --> java, java-design
    • summary: CompareObjectsWithEquals: == ok for enums --> [java] CompareObjectsWithEquals: == ok for enums
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,2 +1,4 @@
    +Rule: [CompareObjectsWithEquals](http://pmd.github.io/latest/pmd-java/rules/java/design.html#CompareObjectsWithEquals)
    +
     I think, comparison with == and != is ok e.g. for enums. 
     Could one modify this rule accordingly? 
    
     
  • Andreas Dangel

    Andreas Dangel - 2016-08-12

    In order to be able to differ between ordinary Objects and Enums, PMD needs to use typeresolution. It needs to detect, that the object is actually a enum. It should be sufficient, if PMD finds on one side an enum.

     
  • Juan Sotuyo

    Juan Sotuyo - 2017-02-06
    • status: open --> not-reproducible
     
  • Juan Sotuyo

    Juan Sotuyo - 2017-02-06

    The issue is not reproducible provided PMD is run with an appropriate auxclasspath.

    The rule currently checks if both ends of the check are of the same type, and they are enums, and will work as expected.

    Make sure you are providing PMD with a full auxclasspath

     

Log in to post a comment.