Law of Demeter: False positives and negatives
A source code analyzer
Brought to you by:
adangel,
juansotuyo
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
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.
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..
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