Fix NPEs
This commit is contained in:
@ -155,7 +155,7 @@ public class DoubleCheckedLockingRule extends AbstractJavaRule {
|
||||
ASTVariableInitializer initializer = null;
|
||||
for (ASTLocalVariableDeclaration l : locals) {
|
||||
ASTVariableDeclaratorId id = l.getFirstDescendantOfType(ASTVariableDeclaratorId.class);
|
||||
if (id.hasImageEqualTo(returnVariableName)) {
|
||||
if (id != null && id.hasImageEqualTo(returnVariableName)) {
|
||||
initializer = l.getFirstDescendantOfType(ASTVariableInitializer.class);
|
||||
break;
|
||||
}
|
||||
@ -164,12 +164,15 @@ public class DoubleCheckedLockingRule extends AbstractJavaRule {
|
||||
if (initializer == null) return false;
|
||||
|
||||
// verify the value with which the local variable is initialized
|
||||
if (initializer.jjtGetChild(0) instanceof ASTExpression
|
||||
if (initializer.jjtGetNumChildren() > 0 && initializer.jjtGetChild(0) instanceof ASTExpression
|
||||
&& initializer.jjtGetChild(0).jjtGetNumChildren() > 0
|
||||
&& initializer.jjtGetChild(0).jjtGetChild(0) instanceof ASTPrimaryExpression
|
||||
&& initializer.jjtGetChild(0).jjtGetChild(0).jjtGetNumChildren() > 0
|
||||
&& initializer.jjtGetChild(0).jjtGetChild(0).jjtGetChild(0) instanceof ASTPrimaryPrefix
|
||||
&& initializer.jjtGetChild(0).jjtGetChild(0).jjtGetChild(0).jjtGetNumChildren() > 0
|
||||
&& initializer.jjtGetChild(0).jjtGetChild(0).jjtGetChild(0).jjtGetChild(0) instanceof ASTName) {
|
||||
ASTName name = (ASTName)initializer.jjtGetChild(0).jjtGetChild(0).jjtGetChild(0).jjtGetChild(0);
|
||||
if (!volatileFields.contains(name.getImage())) {
|
||||
if (name == null || !volatileFields.contains(name.getImage())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@ -185,7 +188,7 @@ public class DoubleCheckedLockingRule extends AbstractJavaRule {
|
||||
Node expression = n.getNthParent(3);
|
||||
if (expression instanceof ASTEqualityExpression) continue;
|
||||
if (expression instanceof ASTStatementExpression) {
|
||||
if (expression.jjtGetChild(1) instanceof ASTAssignmentOperator) {
|
||||
if (expression.jjtGetNumChildren() > 2 && expression.jjtGetChild(1) instanceof ASTAssignmentOperator) {
|
||||
ASTName value = expression.jjtGetChild(2).getFirstDescendantOfType(ASTName.class);
|
||||
if (value == null || !volatileFields.contains(value.getImage())) {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user