Fix exception in FallThrough Check for nested switch statements. #837

This commit is contained in:
Michal Kordas 2015-05-12 21:44:58 +02:00 committed by Roman Ivanov
parent cda369e9cb
commit 7fdcaa5929
3 changed files with 14 additions and 1 deletions

View File

@ -309,7 +309,7 @@ public class FallThroughCheck extends Check
{
final DetailAST caseBody =
caseGroup.findFirstToken(TokenTypes.SLIST);
isTerminated &= isTerminated(caseBody, false, useContinue);
isTerminated = caseBody != null && isTerminated(caseBody, false, useContinue);
caseGroup = caseGroup.getNextSibling();
}
return isTerminated;

View File

@ -45,6 +45,7 @@ public class FallThroughCheckTest extends BaseCheckTestSupport
"369:11: " + getCheckMessage(MSG_FALL_THROUGH),
"372:11: " + getCheckMessage(MSG_FALL_THROUGH),
"374:40: " + getCheckMessage(MSG_FALL_THROUGH),
"416:13: " + getCheckMessage(MSG_FALL_THROUGH),
};
verify(checkConfig,
getPath("coding" + File.separator + "InputFallThrough.java"),
@ -69,6 +70,7 @@ public class FallThroughCheckTest extends BaseCheckTestSupport
"372:11: " + getCheckMessage(MSG_FALL_THROUGH),
"374:40: " + getCheckMessage(MSG_FALL_THROUGH),
"376:11: " + getCheckMessage(MSG_FALL_THROUGH_LAST),
"416:13: " + getCheckMessage(MSG_FALL_THROUGH),
};
verify(checkConfig,
getPath("coding" + File.separator + "InputFallThrough.java"),
@ -112,6 +114,7 @@ public class FallThroughCheckTest extends BaseCheckTestSupport
"348:11: " + getCheckMessage(MSG_FALL_THROUGH),
"351:11: " + getCheckMessage(MSG_FALL_THROUGH),
"353:30: " + getCheckMessage(MSG_FALL_THROUGH),
"416:13: " + getCheckMessage(MSG_FALL_THROUGH),
};
verify(checkConfig,
getPath("coding" + File.separator + "InputFallThrough.java"),

View File

@ -406,4 +406,14 @@ public class InputFallThrough
default:
}
}
void nestedSwitches() {
switch (hashCode()) {
case 1:
switch (hashCode()) { // causing NullPointerException in the past
case 1:
}
default: // violation - no fall through comment
}
}
}