"java-coupling" rule results in error
Closed this issue ยท 2 comments
efueger commented
Bug
Actual Behavior
When using the "java-coupling"
rule, the PMD engine errors with the following error message:
.codeclimate.yml
---
engines:
pmd:
enabled: true
config:
rules:
# - "java-basic"
# - "java-code-size"
- "java-coupling"
ratings:
paths:
- "**.java"
- Removed misconfigured rule: LoosePackageCoupling cause: No packages or classes specified
{"type":"issue","check_name":"LawOfDemeter","description":"Potential violation of Law of Demeter (method chain calls)","content":{"body":"## LawOfDemeter\n\nSince: PMD 5.0\n\nPriority: Medium\n\nCategories: Style\n\nRemediation Points: 50000\n\nThe Law of Demeter is a simple rule, that says 'only talk to friends'. It helps to reduce coupling between classes or objects. See also the references: Andrew Hunt, David Thomas, and Ward Cunningham. The Pragmatic Programmer. From Journeyman to Master. Addison-Wesley Longman, Amsterdam, October 1999.; K.J. Lieberherr and I.M. Holland. Assuring good style for object-oriented programs. Software, IEEE, 6(5):38โ48, 1989.; http://www.ccs.neu.edu/home/lieber/LoD.html; http://en.wikipedia.org/wiki/Law_of_Demeter\n\n### Example:\n\njava\n\n\npublic class Foo {\n /**\n * This example will result in two violations.\n */\n public void example(Bar b) {\n // this method call is ok, as b is a parameter of 'example'\n C c = b.getC();\n \n // this method call is a violation, as we are using c, which we got from B.\n // We should ask b directly instead, e.g. 'b.doItOnC();'\n c.doIt();\n \n // this is also a violation, just expressed differently as a method chain without temporary variables.\n b.getC().doIt();\n \n // a constructor call, not a method call.\n D d = new D();\n // this method call is ok, because we have create the new instance of D locally.\n d.doSomethingElse(); \n }\n}\n\n \n
\n\n### PMD properties\n\nName | Value | Description\n--- | --- | ---\nviolationSuppressRegex | | Suppress violations with messages matching a regular expression\nviolationSuppressXPath | | Suppress violations on nodes which match a given relative XPath expression.\n"},"categories":["Style"],"location":{"path":"extensions/geode-modules-session-internal/src/main/java/org/apache/geode/modules/session/internal/common/AbstractSessionCache.java","lines":{"begin":72,"end":72}},"severity":"normal","remediation_points":50000}
- Tried reproducing with the CLI, but am waiting for it to be updated with PMD's stable channel.
- not sure if this is a PMD issue, or specific to the engine
- sample oss repo: https://github.com/efueger/geode
- found a conversation about the error here: noveogroup/android-check#9
filipesperandio commented
Hey, @efueger! This rule is a bit tricky, I'd suffered with it before too.
It requires configuration, so you can't simply enable it with the string array approach.
To be able to use it, you need a rulset.xml
well configured.
I have an example here just for that coupling
ruleset. Attention to this part where you have to explicitly tell which packages/classes you allow/disallow coupling.
I personally don't use the rule.
efueger commented
Thanks @filipesperandio ๐ . I'll reach out to the customer and let them know.