Menu

#999 Law of Demeter: False positives and negatives

PMD-5.0.3
closed
pmd (543)
PMD
3-Major
Bug
2013-04-05
2012-03-30
No

Hi,
I testet the LawOfDemeterRule in PMD 5.0-alpha.

Thats no Violation in PMD:
public boolean compare(final String aString) {
return aString.equals("S")
}

Thats a Violation in PMD:
public boolean compare(final String aString) {
return "A".equals(aString);
}

Object creation like Object.create() are Violation, if i use the created Object.
Also buffer.append("string").append("string").append("string")...

AFAIK, theses examples aren't Violations.

Best Regards
Stefan Strobel

Discussion

  • Romain PELISSE

    Romain PELISSE - 2013-01-29
    • assigned_to: Tom Copeland --> nobody
    • milestone: --> PMD-5.0.x
     
  • Stefan  Strobel

    Stefan Strobel - 2013-01-30

    I changed the code six month ago to fit the rules of LOD.
    Doesn't work pretty well yet but i could have another look and fix some issues.

     
  • Romain PELISSE

    Romain PELISSE - 2013-01-30

    Hi Stefan,

    If you have working fixes, even if it is a bit ugly, please publish on github ! Assuming it does not degrade the performance of the rule, I'll be OK to merge it..

     
  • Andreas Dangel

    Andreas Dangel - 2013-03-17

    I adjusted the rule to detect the cases you mentioned. I'm sure, there are a lot more cases, where this rule detects false positives or doesn't detect violations.

    If you find such cases, please open a new bug.

    Thanks,
    Andreas

     
  • Andreas Dangel

    Andreas Dangel - 2013-03-17
    • summary: Law of Demeter --> Law of Demeter: False positives and negatives
    • status: open --> in-progress
    • assigned_to: Andreas Dangel
    • module: --> PMD
    • milestone: PMD-5.0.x --> PMD-5.0.3
    • priority: 5 --> 3-Major
    • type: --> Bug
    • affects_version: -->
     
  • Andreas Dangel

    Andreas Dangel - 2013-03-17
    • status: in-progress --> closed
     

Log in to post a comment.