A RetroSearch Logo

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

Search Query:

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

[java] StringToString doesn't trigger on `Bar.class.getSimpleName().toString()` · Issue #3437 · pmd/pmd · GitHub

Affects PMD Version:

6.37

Rule:

Please provide the rule name and a link to the rule documentation:

StringToString
https://pmd.github.io/latest/pmd_rules_java_performance.html#stringtostring

Description:

Code Sample demonstrating the issue:

public class Foo {
  @Override
  public String toString() {
    return new StringJoiner(",", Bar.class.getSimpleName().toString() + "[", "]");
  }
}

Expected outcome:

PMD should report a violation at line

return new StringJoiner(",", Bar.class.getSimpleName().toString() + "[", "]")

but doesn't. This is a false-negative.

This seems to be documented in the Javadoc of the rule

Note: due to an issue with type resolution, this implementation doesn't detect cases when toString() call is chained to a method returning String which is not declared in the class having the call or the call arguments are not of the exact same type as method parameters are, excluding the case when method name and number of it's parameters is enough to identify the method.

Is this limitation something that could be addressed with an additional Rule using XPath 2.0 ?

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