You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] ConsecutiveAppendsShouldReuse: False positive within if-statement without curly braces #4910
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:
StringBuildermessage = newStringBuilder();
if (nameOfOther == null)
message.append(validator.configuration().stringMappers().toString(other));
elsemessage.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));
changed the title [-][java] if-statement triggers ConsecutiveAppendsShouldReuse[/-][+][java] ConsecutiveAppendsShouldReuse: False positive within if-statement without curly brackets[/+]on Dec 24, 2025
changed the title [-][java] ConsecutiveAppendsShouldReuse: False positive within if-statement without curly brackets[/-][+][java] ConsecutiveAppendsShouldReuse: False positive within if-statement without curly braces[/+]on Dec 24, 2025
Activity
PimvanderLoos commentedon Jun 29, 2024
Still happens on 7.3.0.
Specifically, the issue seems to trigger when omitting the curly braces for both the if-clause and the else-clause.
For example, the
foomethod below will triggerConsecutiveAppendsShouldReuse. The methodsbar,baz, andquxwill not trigger the rule.[-][java] if-statement triggers ConsecutiveAppendsShouldReuse[/-][+][java] ConsecutiveAppendsShouldReuse: False positive within if-statement without curly brackets[/+][-][java] ConsecutiveAppendsShouldReuse: False positive within if-statement without curly brackets[/-][+][java] ConsecutiveAppendsShouldReuse: False positive within if-statement without curly braces[/+][doc] Update release notes (#4910, #6313)
[java] Fix pmd#4910: if-statement triggers ConsecutiveAppendsShouldRe…
RM-37163: CPD 7.21.0 upgrade (#8)