EA-76065 - IAE: UsageInfo.<init> (NPE during "find in path" with files=*.png, text=empty)

This commit is contained in:
Alexey Kudravtsev
2015-12-01 12:55:41 +03:00
parent 5bf39501f1
commit c328eefec6
3 changed files with 33 additions and 20 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@ public class UsageInfo {
}
public UsageInfo(@NotNull SmartPsiElementPointer<?> smartPointer,
SmartPsiFileRange psiFileRange,
@Nullable SmartPsiFileRange psiFileRange,
boolean dynamicUsage,
boolean nonCodeUsage) {
myDynamicUsage = dynamicUsage;
@@ -88,21 +88,13 @@ public class UsageInfo {
mySmartPointer = smartPointer;
}
@NotNull
public SmartPsiElementPointer<?> getSmartPointer() {
return mySmartPointer;
}
public SmartPsiFileRange getPsiFileRange() {
return myPsiFileRange;
}
public boolean isNonCodeUsage() {
return isNonCodeUsage;
}
public void setDynamicUsage(boolean dynamicUsage) {
myDynamicUsage = dynamicUsage;
// in case of find file by name, not by text inside. Since it can be a binary file, do not query for text offsets.
public UsageInfo(@NotNull PsiFile psiFile) {
Project project = psiFile.getProject();
SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(project);
mySmartPointer = smartPointerManager.createSmartPsiElementPointer(psiFile);
myPsiFileRange = null;
isNonCodeUsage = true;
}
public UsageInfo(@NotNull PsiElement element, boolean isNonCodeUsage) {
@@ -126,6 +118,23 @@ public class UsageInfo {
this(element, false);
}
@NotNull
public SmartPsiElementPointer<?> getSmartPointer() {
return mySmartPointer;
}
public SmartPsiFileRange getPsiFileRange() {
return myPsiFileRange;
}
public boolean isNonCodeUsage() {
return isNonCodeUsage;
}
public void setDynamicUsage(boolean dynamicUsage) {
myDynamicUsage = dynamicUsage;
}
@Nullable
public PsiElement getElement() { // SmartPointer is used to fix SCR #4572, hotya eto krivo i nado vse perepisat'
return mySmartPointer.getElement();
@@ -209,13 +218,18 @@ public class UsageInfo {
}
public boolean isValid() {
if (myPsiFileRange == null && getElement() instanceof PsiFile) {
return true; // in case of binary file
}
return getSegment() != null;
}
@Nullable
public Segment getSegment() {
PsiElement element = getElement();
if (element == null) return null;
if (element == null
// in case of binary file
|| myPsiFileRange == null && element instanceof PsiFile) return null;
TextRange range = element.getTextRange();
TextRange.assertProperRange(range, element);
if (element instanceof PsiFile) {
@@ -247,7 +247,7 @@ public class FindInProjectUtil {
if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return consumer.process(new UsageInfo(psiFile,0,0,true));
return consumer.process(new UsageInfo(psiFile));
}
})) {
throw new ProcessCanceledException();
@@ -116,7 +116,6 @@ public class ChunkExtractor {
Project project = file.getProject();
myDocument = PsiDocumentManager.getInstance(project).getDocument(file);
LOG.assertTrue(myDocument != null);
final FileType fileType = file.getFileType();
SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, file.getVirtualFile());
highlighter = highlighter == null ? new PlainSyntaxHighlighter() : highlighter;