[java] InsufficientStringBufferDeclaration: Fix CCE for Character
Fixes #5314
This commit is contained in:
+7
-1
@@ -240,6 +240,12 @@ public class InsufficientStringBufferDeclarationRule extends AbstractJavaRulecha
|
||||
|
||||
private int calculateExpression(ASTExpression expression) {
|
||||
Object value = expression.getConstValue();
|
||||
return value == null ? State.UNKNOWN_CAPACITY : (Integer) value;
|
||||
if (value == null) {
|
||||
return State.UNKNOWN_CAPACITY;
|
||||
}
|
||||
if (value instanceof Character) {
|
||||
return (Character) value;
|
||||
}
|
||||
return (Integer) value;
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -1419,4 +1419,23 @@ public class LiteralExpression {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#5314 [java] InsufficientStringBufferDeclarationRule: Lack of handling for char type parameters</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class StringBufferInstantiationWithCharTest {
|
||||
public void example01() {
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
||||
Reference in New Issue
Block a user