mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: even more precise rethrow types (IJ-CR-13170)
GitOrigin-RevId: 34d767e800b3dc24d11fa05e6d237b88b630cb0c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6f7d008170
commit
333c564c62
+5
-3
@@ -131,7 +131,10 @@ public class PsiCatchSectionImpl extends CompositePsiElement implements PsiCatch
|
||||
private static List<PsiType> computePreciseCatchTypes(PsiType declaredType, List<PsiType> uncaughtTypes) {
|
||||
List<PsiType> types = new SmartList<>();
|
||||
for (PsiType type : uncaughtTypes) {
|
||||
if (declaredType.isAssignableFrom(type) ||
|
||||
if (type.isAssignableFrom(declaredType)) {
|
||||
types.add(declaredType);
|
||||
}
|
||||
else if (declaredType.isAssignableFrom(type) ||
|
||||
// JLS 11.2.3 "Exception Checking":
|
||||
// "It is a compile-time error if a catch clause can catch checked exception class E1 and it is not the case
|
||||
// that the try block corresponding to the catch clause can throw a checked exception class that is
|
||||
@@ -142,8 +145,7 @@ public class PsiCatchSectionImpl extends CompositePsiElement implements PsiCatch
|
||||
}
|
||||
}
|
||||
// ... the throw statement throws precisely the set of exception types T.
|
||||
if (!types.isEmpty()) return Collections.unmodifiableList(types);
|
||||
return Collections.singletonList(declaredType);
|
||||
return types;
|
||||
}
|
||||
|
||||
private static Collection<PsiClassType> getThrownTypes(@NotNull PsiTryStatement statement) {
|
||||
|
||||
+18
@@ -277,4 +277,22 @@ class C {
|
||||
}
|
||||
catch (E ignored) {}
|
||||
}
|
||||
|
||||
private void m17() throws InterruptedException, java.io.FileNotFoundException {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
throw new java.io.FileNotFoundException();
|
||||
} catch (InterruptedException | java.io.IOException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private void m18() throws InterruptedException {
|
||||
try {
|
||||
Thread.sleep(1L);
|
||||
// no IOException thrown
|
||||
} catch (<error descr="Exception 'java.io.IOException' is never thrown in the corresponding try block">java.io.IOException ex</error>) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user