Issue #3509: fixed try with resource on FallThroughCheck

This commit is contained in:
rnveach 2017-01-05 16:02:04 -05:00 committed by Roman Ivanov
parent 0844fffc64
commit 32285aadd7
3 changed files with 85 additions and 1 deletions

View File

@ -267,7 +267,13 @@ public class FallThroughCheck extends AbstractCheck {
}
if (!isTerminated) {
isTerminated = isTerminated(ast.getFirstChild(),
DetailAST firstChild = ast.getFirstChild();
if (firstChild.getType() == TokenTypes.RESOURCE_SPECIFICATION) {
firstChild = firstChild.getNextSibling();
}
isTerminated = isTerminated(firstChild,
useBreak, useContinue);
DetailAST catchStmt = ast.findFirstToken(TokenTypes.LITERAL_CATCH);

View File

@ -132,6 +132,11 @@ public class FallThroughCheckTest extends BaseCheckTestSupport {
"424:9: " + getCheckMessage(MSG_FALL_THROUGH),
"436:9: " + getCheckMessage(MSG_FALL_THROUGH),
"446:9: " + getCheckMessage(MSG_FALL_THROUGH),
"491:9: " + getCheckMessage(MSG_FALL_THROUGH),
"495:9: " + getCheckMessage(MSG_FALL_THROUGH),
"501:9: " + getCheckMessage(MSG_FALL_THROUGH),
"507:9: " + getCheckMessage(MSG_FALL_THROUGH),
"514:9: " + getCheckMessage(MSG_FALL_THROUGH),
};
verify(checkConfig,
getPath("InputFallThrough.java"),

View File

@ -448,4 +448,77 @@ public class InputFallThrough
break;
}
}
void tryResource() throws Exception {
switch (hashCode()) {
case 1:
try (final Resource resource = new Resource()) {
return;
}
case 2:
try (final Resource resource = new Resource()) {
return;
}
finally {
return;
}
case 3:
try (final Resource resource = new Resource()) {
return;
}
catch (Exception ex) {
return;
}
case 4:
try (final Resource resource = new Resource()) {
}
finally {
return;
}
case 5:
try (final Resource resource = new Resource()) {
return;
}
finally {
}
case 6:
try (final Resource resource = new Resource()) {
}
catch (Exception ex) {
return;
}
// fallthru
case 7:
try (final Resource resource = new Resource()) {
}
// fallthru
case 8:
try (final Resource resource = new Resource()) {
}
finally {
}
// fallthru
case 9:
try (final Resource resource = new Resource()) {
}
catch (Exception ex) {
}
// fallthru
case 10:
try (final Resource resource = new Resource()) {
return;
}
catch (Exception ex) {
}
// fallthru
default:
break;
}
}
private static class Resource implements AutoCloseable {
@Override
public void close() throws Exception {
}
}
}