diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryWithResourcesPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryWithResourcesPostfixTemplate.java index 843c19e072c0..9e857ad9ce95 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryWithResourcesPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryWithResourcesPostfixTemplate.java @@ -100,7 +100,7 @@ public class TryWithResourcesPostfixTemplate extends PostfixTemplate { @NotNull private static Collection getUnhandled(@NotNull PsiExpression expression) { assert expression.getType() != null; - PsiMethod methodCloser = PsiUtil.getResourceCloserMethodForType((PsiClassType)expression.getType(), expression.getProject()); + PsiMethod methodCloser = PsiUtil.getResourceCloserMethodForType((PsiClassType)expression.getType()); PsiSubstitutor substitutor = PsiUtil.resolveGenericsClassInType(expression.getType()).getSubstitutor(); return methodCloser != null diff --git a/java/java-psi-api/src/com/intellij/psi/util/PsiUtil.java b/java/java-psi-api/src/com/intellij/psi/util/PsiUtil.java index f6b2bbe46940..25288b3d9e90 100644 --- a/java/java-psi-api/src/com/intellij/psi/util/PsiUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/util/PsiUtil.java @@ -998,14 +998,15 @@ public final class PsiUtil extends PsiUtilCore { public static PsiMethod getResourceCloserMethod(@NotNull final PsiResourceVariable resource) { final PsiType resourceType = resource.getType(); if (!(resourceType instanceof PsiClassType)) return null; - return getResourceCloserMethodForType((PsiClassType)resourceType, resource.getProject()); + return getResourceCloserMethodForType((PsiClassType)resourceType); } @Nullable - public static PsiMethod getResourceCloserMethodForType(@NotNull final PsiClassType resourceType, Project project) { + public static PsiMethod getResourceCloserMethodForType(@NotNull final PsiClassType resourceType) { final PsiClass resourceClass = resourceType.resolve(); if (resourceClass == null) return null; + final Project project = resourceClass.getProject(); final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project)); if (autoCloseable == null) return null; diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java index b989c3054b06..552c7e2d9ff5 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java @@ -403,13 +403,16 @@ public class ExceptionUtil { final boolean includeSelfCalls) { final JavaResolveResult result = methodCall.resolveMethodGenerics(); final PsiMethod method = (PsiMethod)result.getElement(); + if (method == null) { + return Collections.emptyList(); + } final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class); if (!includeSelfCalls && method == containingMethod) { return Collections.emptyList(); } final PsiSubstitutor substitutor = result.getSubstitutor(); - if (method != null && !isArrayClone(method, methodCall) && methodCall instanceof PsiMethodCallExpression) { + if (!isArrayClone(method, methodCall) && methodCall instanceof PsiMethodCallExpression) { final PsiClassType[] thrownExceptions = method.getThrowsList().getReferencedTypes(); if (thrownExceptions.length > 0) { final PsiFile containingFile = (containingMethod == null ? methodCall : containingMethod).getContainingFile(); @@ -537,11 +540,11 @@ public class ExceptionUtil { } @NotNull - public static List getUnhandledExceptions(@Nullable PsiMethod method, - PsiElement element, - PsiElement topElement, - @NotNull PsiSubstitutor substitutor) { - if (method == null || isArrayClone(method, element)) { + public static List getUnhandledExceptions(@NotNull PsiMethod method, + PsiElement element, + PsiElement topElement, + @NotNull PsiSubstitutor substitutor) { + if (isArrayClone(method, element)) { return Collections.emptyList(); } final PsiClassType[] referencedTypes = method.getThrowsList().getReferencedTypes();