GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] StringToString doesn't trigger on `Bar.class.getSimpleName().toString()` · Issue #3437 · pmd/pmd

[java] StringToString doesn't trigger on Bar.class.getSimpleName().toString() #3437

New issue
Copy link
New issue
Copy link
Closed
#4154
Closed
[java] StringToString doesn't trigger on Bar.class.getSimpleName().toString()#3437
#4154
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of codein:type-resolutionAffects the type resolution code
Milestone
6.51.0

Description

@ajeans
ajeans
opened on Aug 3, 2021
Issue body actions

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]

Activity

  1. ajeans
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Aug 3, 2021
  2. oowekyala commented on Aug 7, 2021

    @oowekyala
    oowekyala
    on Aug 7, 2021
    Member
    More actions

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

    No, this is a limitation in our type resolution and XPath has less expressive access to that API as Java. So if a java rule cannot do it, an XPath rule couldn't either. Also I think adding new rules to fix limitations of existing ones should be avoided.

    But thanks for the report, it's helpful as it will allow us to better track this documented limitation and fix it eventually.

    Reacted by Arnaud Jeansen
  3. oowekyala
    added
    in:type-resolutionAffects the type resolution code
    on Aug 7, 2021
  4. adangel
    changed the title [-][java] Rule StringToString doesn't trigger on `Bar.class.getSimpleName().toString()`[/-] [+][java] StringToString doesn't trigger on `Bar.class.getSimpleName().toString()`[/+] on Oct 13, 2022
  5. adangel
    added 2 commits that reference this issue on Oct 13, 2022

    [java] Support class literal in type resolution

    This issue will close once commit 1f26319 is merged into the 'main' branch.
    1f26319

    [doc] Update release notes (pmd#2080, pmd#3437, pmd#3681, pmd#3977)

    This issue will close once commit 39c26d9 is merged into the 'main' branch.
    39c26d9
  6. adangel
    added this to the 6.51.0 milestone on Oct 13, 2022
  7. adangel
    closed this as completedin 1f26319on Oct 28, 2022
  8. adangel
    closed this as completedin #4154on Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of codein:type-resolutionAffects the type resolution code

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.51.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.