Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] A false negative about the rule StringBufferInstantiationWithChar #4042

Closed
Zustin opened this issue Jul 15, 2022 · 0 comments · Fixed by #5013
Closed

[java] A false negative about the rule StringBufferInstantiationWithChar #4042

Zustin opened this issue Jul 15, 2022 · 0 comments · Fixed by #5013
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@Zustin
Copy link

Zustin commented Jul 15, 2022

Affects PMD Version:
6.47.0+
7.0.0

Rule:StringBufferInstantiationWithChar

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_errorprone.html#stringbufferinstantiationwithchar

Description:
Hi, I found a false negative about the rule StringBufferInstantiationWithChar, please read the following minimized code example. In line 3, builder is initialized by a character, but ch could converted into an integer. Hence, I think this is a false negative, and maybe we should analyze variable type about this rule.

Code Sample demonstrating the issue:

public void foo() {
    char ch = 'c';
    StringBuilder builder = new StringBuilder(ch);  // should report a warning in this line
}

Expected outcome:A warning

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

Running PMD through: [Maven]

@Zustin Zustin added the a:false-negative PMD doesn't flag a problematic piece of code label Jul 15, 2022
@jsotuyod jsotuyod added the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 17, 2024
@jsotuyod jsotuyod changed the title A false negative about the rule StringBufferInstantiationWithChar [java] A false negative about the rule StringBufferInstantiationWithChar Mar 23, 2024
@jsotuyod jsotuyod removed the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 23, 2024
@jsotuyod jsotuyod added this to the 7.2.0 milestone May 14, 2024
jsotuyod added a commit that referenced this issue May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants