Java control flow: Detect unreachable code when a break or continue in the try block is overridden in the finally block of the same try statement (IDEA-35597)

This commit is contained in:
Pavel Dolgov
2016-07-29 14:54:49 +03:00
parent 3e3b40df65
commit 7b97664b85
3 changed files with 98 additions and 11 deletions
@@ -402,3 +402,69 @@ class Good3 {
return false;
}
}
class ContinueFromFinally {
void foo() {
while (true) {
try {
break;
} finally {
continue;
}
}
<error descr="Unreachable statement">System.out.println();</error>
}
}
class BreakFromNestedTry {
void foo() {
outer:
{
inner:
try {
try {
break inner;
} finally {
System.out.println();
}
} finally {
break outer;
}
<error descr="Unreachable statement">System.out.println();</error>
}
}
}
class BreakFromNestedFinally {
void foo() {
outer:
{
inner:
try {
try {
} finally {
break inner;
}
} finally {
break outer;
}
<error descr="Unreachable statement">System.out.println();</error>
}
}
}
class ContinueFromTry {
void foo() {
outer:
{
do {
try {
continue;
} finally {
break outer;
}
} while (false);
<error descr="Unreachable statement">System.out.println();</error>
}
}
}