resources.report.rules.pmd.InsufficientStringBufferDeclaration.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
InsufficientStringBufferDeclaration
InsufficientStringBufferDeclaration
Failing to pre-size a StringBuffer or StringBuilder properly could cause it to re-size many times during runtime. This rule attempts to determine the total number the characters that are actually passed into StringBuffer.append(), but represents a best guess “worst case” scenario. An empty StringBuffer/StringBuilder constructor initializes the object to 16 characters. This default is assumed if the length of the constructor can not be determined.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.java.rule.strings.InsufficientStringBufferDeclarationRule
Example(s):
StringBuffer bad = new StringBuffer();
bad.append("This is a long string that will exceed the default 16 characters");
StringBuffer good = new StringBuffer(41);
good.append("This is a long string, which is pre-sized");
© 2015 - 2024 Weber Informatics LLC | Privacy Policy