mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
precise rethrow: ensure unreachable catch sections do not participate in precise rethrow
This commit is contained in:
+9
-4
@@ -34,6 +34,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -123,12 +124,16 @@ public class PsiCatchSectionImpl extends CompositePsiElement implements PsiCatch
|
||||
}
|
||||
return thrownType;
|
||||
});
|
||||
if (uncaughtTypes.isEmpty()) return Collections.emptyList(); // unreachable catch section
|
||||
// ... and T is assignable to Ej ...
|
||||
// ... the throw statement throws precisely the set of exception types T.
|
||||
if (uncaughtTypes.stream().anyMatch(type -> declaredType.isAssignableFrom(type) ||
|
||||
type instanceof PsiClassType && ExceptionUtil.isUncheckedException((PsiClassType)type))) {
|
||||
return uncaughtTypes;
|
||||
List<PsiType> types = new ArrayList<>();
|
||||
for (PsiType type : uncaughtTypes) {
|
||||
if (declaredType.isAssignableFrom(type) || type instanceof PsiClassType && ExceptionUtil.isUncheckedException((PsiClassType)type)) {
|
||||
types.add(type);
|
||||
}
|
||||
}
|
||||
// ... the throw statement throws precisely the set of exception types T.
|
||||
if (!types.isEmpty()) return types;
|
||||
}
|
||||
|
||||
return Collections.singletonList(declaredType);
|
||||
|
||||
+12
@@ -250,4 +250,16 @@ class C {
|
||||
if (i == 1) throw new E1();
|
||||
if (i == 2) throw new E2();
|
||||
}
|
||||
|
||||
private void m15() throws E1 {
|
||||
try {
|
||||
throw new E1();
|
||||
}
|
||||
catch (final E1 e1) {
|
||||
throw e1;
|
||||
}
|
||||
catch (final E e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user