forked from phoedos/pmd
#1384 NullPointerException in ConsecutiveLiteralAppendsRule
This commit is contained in:
@ -90,7 +90,9 @@ public class ConsecutiveLiteralAppendsRule extends AbstractJavaRule {
|
||||
threshold = getProperty(THRESHOLD_DESCRIPTOR);
|
||||
|
||||
int concurrentCount = checkConstructor(node, data);
|
||||
concurrentCount += checkInitializerExpressions(node);
|
||||
if (hasInitializer(node)) {
|
||||
concurrentCount += checkInitializerExpressions(node);
|
||||
}
|
||||
Node lastBlock = getFirstParentBlock(node);
|
||||
Node currentBlock = lastBlock;
|
||||
Map<VariableNameDeclaration, List<NameOccurrence>> decls = node.getScope().getDeclarations(
|
||||
@ -219,6 +221,10 @@ public class ConsecutiveLiteralAppendsRule extends AbstractJavaRule {
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean hasInitializer(ASTVariableDeclaratorId node) {
|
||||
return node.jjtGetParent().hasDescendantOfType(ASTVariableInitializer.class);
|
||||
}
|
||||
|
||||
private int processAdditive(Object data, int concurrentCount, Node sn, Node rootNode) {
|
||||
ASTAdditiveExpression additive = sn.getFirstDescendantOfType(ASTAdditiveExpression.class);
|
||||
// The additive expression must of be type String to count
|
||||
|
@ -1262,6 +1262,26 @@ public class StringBufferTest {
|
||||
stringBuffer2.append("string ");
|
||||
Log.i(TAG, stringBuffer2.toString());
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1384 NullPointerException in ConsecutiveLiteralAppendsRule - 1</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class ConsecutiveLiteralAppendsRuleTest {
|
||||
private StringBuilder cdata;
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1384 NullPointerException in ConsecutiveLiteralAppendsRule - 2</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class ConsecutiveLiteralAppendsRuleTest {
|
||||
public void appendChar(final StringBuilder s) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -12,4 +12,6 @@
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* [#1384](https://sourceforge.net/p/pmd/bugs/1384/): NullPointerException in ConsecutiveLiteralAppendsRule
|
||||
|
||||
**API Changes:**
|
||||
|
Reference in New Issue
Block a user