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] if-statement triggers ConsecutiveAppendsShouldReuse #4910

Open
cowwoc opened this issue Apr 2, 2024 · 0 comments
Open

[java] if-statement triggers ConsecutiveAppendsShouldReuse #4910

cowwoc opened this issue Apr 2, 2024 · 0 comments
Labels
a:false-positive PMD flags a piece of code that is not problematic

Comments

@cowwoc
Copy link

cowwoc commented Apr 2, 2024

Affects PMD Version:
7.0.0

Rule:

Please provide the rule name and a link to the rule documentation: https://docs.pmd-code.org/latest/pmd_rules_java_performance.html#consecutiveappendsshouldreuse

Description:
It seems that invoking StringBuilder.append() within an if-statement triggers a false-positive of the ConsecutiveAppendsShouldReuse rule. At least, I don't see how the code could be modified to please this rule.

Code Sample demonstrating the issue:

StringBuilder message = new StringBuilder();
if (nameOfOther == null)
	message.append(validator.configuration().stringMappers().toString(other));
else
	message.append(MessageBuilder.quoteName(nameOfOther));
message.append('.');

Error Message:

[INFO] PMD Failure: com.github.cowwoc.requirements.java.internal.implementation.message.ComparableMessages:47 Rule:ConsecutiveAppendsShouldReuse Priority:3 StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable..

where line 47 points to message.append(validator.configuration().stringMappers().toString(other));

Running PMD through: Maven
maven-pmd-plugin 3.21.2

@cowwoc cowwoc added the a:false-positive PMD flags a piece of code that is not problematic label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

No branches or pull requests

1 participant