Skip to content

[java] UselessOperationOnImmutable various false negatives with String #4513

@adangel

Description

@adangel

Affects PMD Version: 6.x

Rule: UselessOperationOnImmutable

Description:

This is already fixed with PMD 7.0.0-rc1.
Found via #3123

Code Sample demonstrating the issue:

public class TestCase {
  public void method1(String s) {
    s.trim();
  }
  public void method2() {
   String.valueOf(0);
  }
  public void method3() {
   String.valueOf(0).trim();
  }
}

Expected outcome:

PMD should report a violation at lines 3,6,9 but doesn't. This is a false-negative.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions