unused declaration: avoid NPE while tree sorting due to RefImplicitConstructor doesn...
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Wed, 27 Jul 2016 07:40:24 +0000 (10:40 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Wed, 27 Jul 2016 07:40:24 +0000 (10:40 +0300)
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsViewComparator.java

index a06afdf762ec34727b7d34384c75302ffcef2364..cb85ba7ae7025494b22a6228ac6e98537a0a78c7 100644 (file)
@@ -38,6 +38,7 @@ import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionsConfigT
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiNamedElement;
 import com.intellij.psi.PsiQualifiedNamedElement;
+import com.intellij.psi.SmartPsiElementPointer;
 import com.intellij.psi.util.PsiUtilCore;
 
 import java.util.Comparator;
@@ -159,12 +160,16 @@ public class InspectionResultsViewComparator implements Comparator {
 
   private static int compareEntities(final RefEntity entity1, final RefEntity entity2) {
     if (entity1 instanceof RefElement && entity2 instanceof RefElement) {
-      final VirtualFile file1 = ((RefElement)entity1).getPointer().getVirtualFile();
-      final VirtualFile file2 = ((RefElement)entity2).getPointer().getVirtualFile();
-      if (file1 != null && Comparing.equal(file1, file2) && file1.isValid()) {
-        final int positionComparing = PsiUtilCore.compareElementsByPosition(((RefElement)entity1).getElement(), ((RefElement)entity2).getElement());
-        if (positionComparing != 0) {
-          return positionComparing;
+      final SmartPsiElementPointer p1 = ((RefElement)entity1).getPointer();
+      final SmartPsiElementPointer p2 = ((RefElement)entity2).getPointer();
+      if (p1 != null && p2 != null) {
+        final VirtualFile file1 = p1.getVirtualFile();
+        final VirtualFile file2 = p2.getVirtualFile();
+        if (file1 != null && Comparing.equal(file1, file2) && file1.isValid()) {
+          final int positionComparing = PsiUtilCore.compareElementsByPosition(((RefElement)entity1).getElement(), ((RefElement)entity2).getElement());
+          if (positionComparing != 0) {
+            return positionComparing;
+          }
         }
       }
     }