InefficientEmptyStringCheck: Fix NPE
This commit is contained in:
@ -56,7 +56,7 @@ public class InefficientEmptyStringCheckRule extends AbstractInefficientZeroChec
|
|||||||
|
|
||||||
Node prevCall = node.jjtGetChild(node.jjtGetNumChildren() - 4);
|
Node prevCall = node.jjtGetChild(node.jjtGetNumChildren() - 4);
|
||||||
String target = prevCall.jjtGetNumChildren() > 0 ? prevCall.jjtGetChild(0).getImage() : prevCall.getImage();
|
String target = prevCall.jjtGetNumChildren() > 0 ? prevCall.jjtGetChild(0).getImage() : prevCall.getImage();
|
||||||
if (target != null && "trim".equals(target) || target.endsWith(".trim")) {
|
if (target != null && ("trim".equals(target) || target.endsWith(".trim"))) {
|
||||||
addViolation(data, node);
|
addViolation(data, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,5 +179,18 @@ public class Foo {
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>Verify no NPE is thrown</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
void bar() {
|
||||||
|
if (super.guardStmtByLogLevel.isEmpty() && logLevels.length > 0 && guardMethods.length > 0) {
|
||||||
|
configureGuards(logLevels, guardMethods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
</test-data>
|
</test-data>
|
||||||
|
Reference in New Issue
Block a user