A RetroSearch Logo

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

Search Query:

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

[java] StringToString false-positive with local method name confusion · Issue #3977 · pmd/pmd · GitHub

Affects PMD Version: 6.43.0

Rule: StringToString

Description:

When you have a method chain call and at the end the toString() call. And there is a local method with the same name as the method call, then this rule is confused. If the local method returns a String, then this rule is triggered.

The rule searches always for local method declarations, but that's wrong - at least for method chains.

Code Sample demonstrating the issue:

public class StringToString_FP {
  private String s;

  public void print(A a) {
    this.s = a.getB().getC().toString(); // line 5 - false positive
    this.s = String.valueOf(a.getB().getC()); // workaround
    System.out.println(s);
  }

  public String getC() {
    return "";
  }
}

interface A {
    B getB();
}

interface B {
    Character getC();
}

B::getC returns a Character, StringToString_FP::getC returns a String.
At line 5, B::getC is called.

Expected outcome:

PMD reports a violation at line 5, but that's wrong. That's a false positive.


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