A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2174 below:

False positive with 'this' pointer · Issue #2174 · pmd/pmd · GitHub

#2160 (comment)

Affects PMD Version:
6.20.0

Rule:
LawOfDemeter

Description:
LawOfDemeter does not recognise 'this' pointer and includes its dot accessor as a count towards method chaining. It must not. Similarly for 'super' while calling parent class functions.

Code Sample demonstrating the issue:

package pmdtests;

public class Foo {
  private final int i;

  public Foo(int i) {
    this.i = i;
  }


  public void meth() {
    System.out.println(this.i); // wrong violation: method chain calls
    System.out.println(super.i); // wrong violation: method chain calls
    System.out.println(i);      // no violation
  }

  public void method(Foo this) {
    System.out.println(this.i);  // wrong violation: method chain calls
  }

  public void method(Foo this, String... args) {
    System.out.println(this.i);  // wrong violation: method chain calls
    for (String arg: args)
      System.out.println(arg);
  }
}

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4