Affects PMD Version:
Rule:
InsufficientStringBufferDeclaration
Description:
When calculating the size of a StringBuilder
at runtime, e.g. by adding the lengths of strings to be appended or by adding constant values e.g. for the output of Date/DecimalFormat will result in a InsufficientStringBufferDeclaration
even if the calculated value will be larger than the length of the constant strings alone.
Code Sample demonstrating the issue:
public String foo(final String x, final String y, final double z, final Date d, final double v) { final StringBuilder sb = new StringBuilder(20 + 9*2 + 16 + 2 * x.length() + y.length()); final DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN); df.applyPattern("#,##0.000"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy hh:mm"); sb.append("foobar") .append(df.format(z)) .append(' ') .append(x) .append(y) .append("foobar") .append(sdf.format(d)) .append("foobar") .append(df.format(v)) .append(' ') .append(x); return sb.toString(); }
Running PMD through: Gradle
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4