jborgers / PMD-jPinpoint-rules

PMD rule set for responsible Java and Kotlin coding: performance, sustainability, multi-threading, data mixup and more.
Apache License 2.0
43 stars 10 forks source link

Fix Request for AvoidUnnecessaryStringBuilderCreation: false positive for non-append operations #427

Closed jborgers closed 1 week ago

jborgers commented 1 week ago

Method reverse is used on the buffer which cannot be replaced by a '+'. This validates the creation of a StringBuilder Example:

StringBuilder timestampBuilder = new StringBuilder(new SimpleDateFormat(TIME_STAMP_FORMAT).format(new Date()));
String reversedTimeStamp = timestampBuilder.reverse().append(userId).toString(); // <--- false positive
jborgers commented 1 week ago

There is more wrong, local var in stead of return,..Created extra unit tests.