collect exceptions by call arguments (IDEA-134808)

This commit is contained in:
Anna Kozlova
2014-12-29 16:13:46 +01:00
parent 658607d9c2
commit b57746c55e
3 changed files with 54 additions and 1 deletions

View File

@@ -107,7 +107,7 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai
final List<PsiClassType> exceptions = ExceptionUtil.ourThrowsGuard.doPreventingRecursion(myExpression, false, new Computable<List<PsiClassType>>() {
@Override
public List<PsiClassType> compute() {
return ExceptionUtil.getUnhandledExceptions(body);
return ExceptionUtil.getUnhandledExceptions(new PsiElement[] {body});
}
});
if (exceptions != null) {

View File

@@ -0,0 +1,49 @@
import java.io.File;
class Test {
public interface A<E extends Throwable> {
Object call() throws E;
}
public interface B<E extends Throwable> {
void call() throws E;
}
static <T, E extends Throwable> T method(A<E> lambda) {
try {
lambda.call();
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
static <E extends Throwable> void method(B<E> lambda) {
try {
lambda.call();
} catch (Throwable e) {
e.printStackTrace();
}
}
static String returns(String s) throws Exception {
System.out.println(s); return null;
}
static void voids(String s) throws Exception {
System.out.println(s);
}
static {
method(() -> {
voids("B");
});
method(() -> voids("B"));
method(() -> {
return new File(returns("A"));
});
method(() -> new File(returns("A")));
}
}

View File

@@ -49,6 +49,10 @@ public class ExceptionVariablesInferenceTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testExceptionsThrownByCallArguments() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}