A RetroSearch Logo

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

Search Query:

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

False positive for chained methods with generic method call · Issue #2175 · pmd/pmd · GitHub

#2160 (comment)

Affects PMD Version:
6.20.0

Rule:
LawOfDemeter

Description:
The rule double counts dot accessor for method that uses angled brackets to specify return type in generic method.

Code Sample demonstrating the issue:

package pmdtests;

import java.util.Arrays;
import java.util.List;

public enum Containment {
  ;

  public static void main(String... args) {
    Object obj = "one";
    List<Object> objs = Arrays.asList("one", 2, Math.PI, 4);
    List<Integer> ints = Arrays.asList(2, 4);
    assert objs.contains(obj);     // wrong violation: object not created locally
    assert objs.containsAll(ints); // wrong violation: object not created locally
    assert !ints.contains(obj);    // wrong violation: object not created locally
    assert !ints.containsAll(objs);// wrong violation: object not created locally

    obj = 1;
    objs = Arrays.<Object>asList(1, 3); // wrong violation: method chain calls
    ints = Arrays.asList(1, 2, 3, 4);
    assert ints.contains(obj);          // wrong violation: object not created locally
    assert ints.containsAll(objs);      // wrong violation: object not created locally
  }
}

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