Question regarding DataIndexer.

Hi,

We have an indexer for a custom file format. In the code below the VirtualFile is set correctly, but sometimes(very rarely), the psiFile is null, with the stack trace at that point given below. What am I doing wrong? In what cases would the psiFile be null?

public class FooDataIndexer implements
      DataIndexer<ProtoIndexKey, ProtoIndexValue, FileContent> {

    @NotNull
    @Override
    public Map<FooIndexKey, FooIndexValue> map(FileContent inputData) {
      Map<FooIndexKey, FooIndexValue> symbols = Maps.newHashMap();
      Project project = inputData.getProject();
      VirtualFile vFile = inputData.getFile();
      PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
      ...
    }
}



Stack trace:
        at com.foopackage.FooDataIndexer.map()

        at com.intellij.util.indexing.MapReduceIndex.update(MapReduceIndex.java:200)
        at com.intellij.util.indexing.FileBasedIndex$20.run(FileBasedIndex.java:1402)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeNonCancelableSection(ProgressManagerImpl.java:132)
        at com.intellij.util.indexing.FileBasedIndex.a(FileBasedIndex.java:1399)
        at com.intellij.util.indexing.FileBasedIndex.indexFileContent(FileBasedIndex.java:1365)
        at com.intellij.util.indexing.FileBasedIndex$ChangedFilesCollector.a(FileBasedIndex.java:1751)
        at com.intellij.util.indexing.FileBasedIndex$ChangedFilesCollector.forceUpdate(FileBasedIndex.java:1716)
        at com.intellij.util.indexing.FileBasedIndex.ensureUpToDate(FileBasedIndex.java:734)
        at com.intellij.psi.stubs.StubIndexImpl.get(StubIndexImpl.java:174)
        at com.intellij.psi.stubs.AbstractStubIndex.get(AbstractStubIndex.java:34)
        at com.intellij.psi.impl.java.stubs.index.JavaSuperClassNameOccurenceIndex.get(JavaSuperClassNameOccurenceIndex.java:45)
        at com.intellij.psi.impl.search.JavaDirectInheritorsSearcher$4.compute(JavaDirectInheritorsSearcher.java:77)
        at com.intellij.psi.impl.search.JavaDirectInheritorsSearcher$4.compute(JavaDirectInheritorsSearcher.java:75)
        at com.intellij.openapi.application.impl.ApplicationImpl$11.run(ApplicationImpl.java:818)
        at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:777)
        at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:816)
        at com.intellij.psi.impl.search.JavaDirectInheritorsSearcher.execute(JavaDirectInheritorsSearcher.java:75)
        at com.intellij.psi.impl.search.JavaDirectInheritorsSearcher.execute(JavaDirectInheritorsSearcher.java:34)
        at com.intellij.util.ExecutorsQuery.processResults(ExecutorsQuery.java:42)
        at com.intellij.util.AbstractQuery.forEach(AbstractQuery.java:67)
        at com.intellij.util.UniqueResultsQuery.process(UniqueResultsQuery.java:58)
        at com.intellij.util.UniqueResultsQuery.forEach(UniqueResultsQuery.java:54)
        at com.intellij.psi.search.searches.ClassInheritorsSearch.processInheritors(ClassInheritorsSearch.java:246)
        at com.intellij.psi.search.searches.ClassInheritorsSearch.access$100(ClassInheritorsSearch.java:45)
        at com.intellij.psi.search.searches.ClassInheritorsSearch$1.execute(ClassInheritorsSearch.java:67)
        at com.intellij.psi.search.searches.ClassInheritorsSearch$1.execute(ClassInheritorsSearch.java:51)
        at com.intellij.util.ExecutorsQuery.processResults(ExecutorsQuery.java:42)
        at com.intellij.util.AbstractQuery.forEach(AbstractQuery.java:67)
        at com.intellij.util.AbstractQuery.findFirst(AbstractQuery.java:47)
        at com.intellij.codeInsight.daemon.impl.JavaLineMarkerProvider.a(JavaLineMarkerProvider.java:171)
        at com.intellij.codeInsight.daemon.impl.JavaLineMarkerProvider.collectSlowLineMarkers(JavaLineMarkerProvider.java:157)
        at com.intellij.codeInsight.daemon.impl.SlowLineMarkersPass.addLineMarkers(SlowLineMarkersPass.java:76)
        at com.intellij.codeInsight.daemon.impl.SlowLineMarkersPass.doCollectInformation(SlowLineMarkersPass.java:64)
        at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:58)
        at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$1$1.run(PassExecutorService.java:348)
        at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1036)
        at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$1.run(PassExecutorService.java:340)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:202)
        at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.a(PassExecutorService.java:338)
        at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:314)
        at com.intellij.concurrency.JobUtil$3.call(JobUtil.java:133)
        at com.intellij.concurrency.JobUtil$3.call(JobUtil.java:130)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at com.intellij.concurrency.PrioritizedFutureTask.access$101(PrioritizedFutureTask.java:31)
        at com.intellij.concurrency.PrioritizedFutureTask$1.run(PrioritizedFutureTask.java:70)
        at com.intellij.concurrency.PrioritizedFutureTask.run(PrioritizedFutureTask.java:113)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)

1 comment
Comment actions Permalink

If your index relies on the PSI, you should build a stub index, not a virtual file index. See http://confluence.jetbrains.net/display/IDEADEV/Indexing+and+PSI+Stubs+in+IntelliJ+IDEA for more information.

0

Please sign in to leave a comment.