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 false-positive with local method name confusion · Issue #3977 · pmd/pmd

[java] StringToString false-positive with local method name confusion #3977

New issue
Copy link
New issue
Copy link
Closed
#4154
Closed
[java] StringToString false-positive with local method name confusion#3977
#4154
Copy link
Assignees
adangel
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.51.0

Description

@adangel
adangel
opened on May 25, 2022
Issue body actions

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.

Activity

  1. adangel
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on May 25, 2022
  2. adangel commented on May 25, 2022

    @adangel
    adangel
    on May 25, 2022
    MemberAuthor
    More actions

    Similar to #2080 - here it is a method declaration, there it is a field declaration.

  3. adangel
    self-assigned this
    on Oct 12, 2022
  4. adangel
    added 2 commits that reference this issue on Oct 13, 2022

    [java] StringToString false-positive with local method name confusion

    This issue will close once commit 3ee4926 is merged into the 'main' branch.
    3ee4926

    [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
  5. adangel
    added this to the 6.51.0 milestone on Oct 13, 2022
  6. adangel
    closed this as completedin 3ee4926on Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @adangel
    adangel

Labels

a:false-positivePMD flags a piece of code that is not problematic

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.