Menu

#868 OverrideBothEqualsAndHashcode bug with interfaces

open
nobody
pmd (543)
5
2012-10-07
2009-04-28
Andreas
No

Hope this is a) a real bug and b) not posted yet (havent found anything here)

OverrideBothEqualsAndHashcode does not work correctly with classes implementing an interface.

Example:

package de.my.package.ui;

// PMD reports correctly a violation prio 1
public class XX {
public boolean equals(Object obj) {
return true;
}
}

package de.my.package.ui;

// PMD does NOT report a violation
public class YY implements java.io.Serializable {
public boolean equals(Object obj) {
return true;
}
}

We are using PMD 4.2.5 and Eclipse 3.4.2

Thanks

Discussion

  • Romain PELISSE

    Romain PELISSE - 2009-04-28

    I failed to reproduce your issue.... Would mind try to reproduce it out of Eclipse (using a pmd command line or inside ant/maven) ?

    Thanks.

     
  • Andreas

    Andreas - 2009-04-28

    I ran PMD on console with the classes above.

    pmd XX.java xml basic

    <pmd version="4.2.5" timestamp="2009-04-28T13:13:45.077">
    <file name="C:\Dokumente und Einstellungen\gisja\Desktop\download\pmd-4.2.5\bin\XX.java">
    <violation beginline="2" endline="2" begincolumn="20" endcolumn="35" rule="OverrideBothEqualsAndHashcode" ruleset="Basic Rules" class="" method="equals" externalinfourl="http://pmd.sourceforge.net/rules/basic.html#OverrideBothEqualsAndHashcode" priority="3">
    Ensure you override both equals() and hashCode()
    </violation>
    </file>
    </pmd>

    So this is correct....

    with the YY.java class:

    pmd YY.java xml basic

    <pmd version="4.2.5" timestamp="2009-04-28T13:14:23.685">
    </pmd>

    Which is NOT correct - should have complained

    This was done with a fresh download of pmd 4.2.5

    Thanks

     
  • Andreas

    Andreas - 2009-09-11

    Any new status for that ?

     

Log in to post a comment.