EA-30271 - NPE: CanBeFinalInspection.checkElement
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 1 Feb 2012 09:32:35 +0000 (13:32 +0400)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 1 Feb 2012 09:43:23 +0000 (13:43 +0400)
java/java-impl/src/com/intellij/codeInspection/canBeFinal/CanBeFinalInspection.java

index d14eb9dc930d5df4596d110a5cd85c35ed7988af..e1d43b13eff6e77b36926a025f40569c76a544c8 100644 (file)
@@ -140,24 +140,24 @@ public class CanBeFinalInspection extends GlobalJavaInspectionTool {
       if (!((RefElementImpl)refElement).checkFlag(CanBeFinalAnnotator.CAN_BE_FINAL_MASK)) return null;
 
       final PsiMember psiMember = (PsiMember)refElement.getElement();
-      if (!CanBeFinalHandler.allowToBeFinal(psiMember)) return null;
+      if (psiMember == null || !CanBeFinalHandler.allowToBeFinal(psiMember)) return null;
 
       PsiIdentifier psiIdentifier = null;
       if (refElement instanceof RefClass) {
         RefClass refClass = (RefClass)refElement;
         if (refClass.isInterface() || refClass.isAnonymous() || refClass.isAbstract()) return null;
         if (!isReportClasses()) return null;
-        psiIdentifier = refClass.getElement().getNameIdentifier();
+        psiIdentifier = ((PsiClass)psiMember).getNameIdentifier();
       }
       else if (refElement instanceof RefMethod) {
         RefMethod refMethod = (RefMethod)refElement;
         if (refMethod.getOwnerClass().isFinal()) return null;
         if (!isReportMethods()) return null;
-        psiIdentifier = ((PsiMethod)refMethod.getElement()).getNameIdentifier();
+        psiIdentifier = ((PsiMethod)psiMember).getNameIdentifier();
       }
       else if (refElement instanceof RefField) {
         if (!isReportFields()) return null;
-        psiIdentifier = ((RefField)refElement).getElement().getNameIdentifier();
+        psiIdentifier = ((PsiField)psiMember).getNameIdentifier();
       }