#1409 NullPointerException in InsufficientStringBufferRule
This commit is contained in:
parent
365e7a1f68
commit
d8d8a9539f
@ -305,13 +305,17 @@ public class InsufficientStringBufferDeclarationRule extends AbstractJavaRule {
|
||||
int size = 0;
|
||||
if (parent != null) {
|
||||
final Node initializer = parent.getFirstChildOfType(ASTVariableInitializer.class);
|
||||
final Node primExp = initializer.getFirstDescendantOfType(ASTPrimaryExpression.class);
|
||||
for (int i = 0; i < primExp.jjtGetNumChildren(); i++) {
|
||||
final Node sn = primExp.jjtGetChild(i);
|
||||
if (!(sn instanceof ASTPrimarySuffix) || sn.getImage() != null) {
|
||||
continue;
|
||||
}
|
||||
size += processNode(sn);
|
||||
if (initializer != null) {
|
||||
final Node primExp = initializer.getFirstDescendantOfType(ASTPrimaryExpression.class);
|
||||
if (primExp != null) {
|
||||
for (int i = 0; i < primExp.jjtGetNumChildren(); i++) {
|
||||
final Node sn = primExp.jjtGetChild(i);
|
||||
if (!(sn instanceof ASTPrimarySuffix) || sn.getImage() != null) {
|
||||
continue;
|
||||
}
|
||||
size += processNode(sn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return size;
|
||||
|
@ -1023,6 +1023,19 @@ public class StringBuilderWithMessageRetrieval {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1409 NullPointerException in InsufficientStringBufferRule</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class NullPointer {
|
||||
public void run(String[] strings) {
|
||||
StringBuilder builder;
|
||||
builder = new StringBuilder();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
* java-controversial/DefaultPackage:
|
||||
[#1410](https://sourceforge.net/p/pmd/bugs/1410/): DefaultPackage triggers on field annotated with @VisibleForTesting
|
||||
* java-strings/InsufficientStringBufferDeclaration:
|
||||
[#1409](https://sourceforge.net/p/pmd/bugs/1409/): NullPointerException in InsufficientStringBufferRule
|
||||
|
||||
**API Changes:**
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user