diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 50df51eaa7a4..de5d470e8e69 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -445,14 +445,18 @@ public class InferenceSession { } else if (acceptObject || upperBounds.size() > 1 || !upperBounds.get(0).equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) { PsiType glb = null; - for (PsiType upperBound : upperBounds) { - upperBound = acceptBoundsWithRecursiveDependencies(typeParameter, upperBound, substitutor); - if (isProperType(upperBound, false)) { - if (glb == null) { - glb = upperBound; - } - else { - glb = GenericsUtil.getGreatestLowerBound(glb, upperBound); + if (isThrowable(upperBounds)) { + glb = PsiType.getJavaLangRuntimeException(myManager, GlobalSearchScope.allScope(myManager.getProject())); + } else { + for (PsiType upperBound : upperBounds) { + upperBound = acceptBoundsWithRecursiveDependencies(typeParameter, upperBound, substitutor); + if (isProperType(upperBound, false)) { + if (glb == null) { + glb = upperBound; + } + else { + glb = GenericsUtil.getGreatestLowerBound(glb, upperBound); + } } } } @@ -473,6 +477,20 @@ public class InferenceSession { return substitutor; } + private static boolean isThrowable(List upperBounds) { + boolean commonThrowable = false; + for (PsiType upperBound : upperBounds) { + if (upperBound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) continue; + if (upperBound.equalsToText(CommonClassNames.JAVA_LANG_EXCEPTION) || + upperBound.equalsToText(CommonClassNames.JAVA_LANG_THROWABLE)) { + commonThrowable = true; + } else { + return false; + } + } + return commonThrowable; + } + private PsiType acceptBoundsWithRecursiveDependencies(PsiTypeParameter typeParameter, PsiType bound, PsiSubstitutor substitutor) { if (!isProperType(bound)) { final PsiSubstitutor subst = PsiUtil.resolveClassInType(bound) != typeParameter ? substitutor.put(typeParameter, null) : substitutor;