All Downloads are FREE. Search and download functionalities are using the official Maven repository.

resources.report.rules.pmd.StringBufferInstantiationWithChar.html Maven / Gradle / Ivy



StringBufferInstantiationWithChar

StringBufferInstantiationWithChar

Individual character values provided as initialization arguments will be converted into integers. This can lead to internal buffer sizes that are larger than expected. Some examples:

new StringBuffer() // 16 new StringBuffer(6) // 6 new StringBuffer(“hello world”) // 11 + 16 = 27 new StringBuffer(‘A’) // chr(A) = 65 new StringBuffer(“A”) // 1 + 16 = 17

new StringBuilder() // 16 new StringBuilder(6) // 6 new StringBuilder(“hello world”) // 11 + 16 = 27 new StringBuilder(‘C’) // chr(C) = 67 new StringBuilder(“A”) // 1 + 16 = 17


//AllocationExpression/ClassOrInterfaceType
[@Image='StringBuffer' or @Image='StringBuilder']
/../Arguments/ArgumentList/Expression/PrimaryExpression
/PrimaryPrefix/
Literal
  [starts-with(@Image, "'")]
  [ends-with(@Image, "'")]

Example(s):


	// misleading instantiation, these buffers
	// are actually sized to 99 characters long
StringBuffer  sb1 = new StringBuffer('c');   
StringBuilder sb2 = new StringBuilder('c');
  
// in these forms, just single characters are allocated
StringBuffer  sb3 = new StringBuffer("c");
StringBuilder sb4 = new StringBuilder("c");





© 2015 - 2024 Weber Informatics LLC | Privacy Policy