Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"java-coupling" rule results in error #21

Closed
efueger opened this issue Oct 6, 2017 · 2 comments
Closed

"java-coupling" rule results in error #21

efueger opened this issue Oct 6, 2017 · 2 comments
Assignees

Comments

@efueger
Copy link
Member

efueger commented Oct 6, 2017

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}

@filipesperandio
Copy link
Contributor

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
Copy link
Member Author

efueger commented Oct 6, 2017

Thanks @filipesperandio 👍 . I'll reach out to the customer and let them know.

@efueger efueger closed this as completed Oct 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants