Java control flow: Don't allow extracting method if there's a potential side effect on the local variables in the case of exception thrown (IDEA-79444, IDEA-159916)

This commit is contained in:
Pavel Dolgov
2016-08-24 15:24:43 +03:00
parent 08a18bc8bd
commit 1a3605e4cb
23 changed files with 713 additions and 141 deletions
@@ -0,0 +1,26 @@
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.ThreadLocalRandom;
public class A {
void f() {
String s = "";
try {
s = "a";
s = newMethod(s);
} finally {
System.out.println(s);
}
}
@NotNull
private String newMethod(String s) {
if (r()) throw new RuntimeException();
s = "b";
return s;
}
private boolean r() {
return ThreadLocalRandom.current().nextBoolean();
}
}