ImageNotReadyException in Command Line tool

I'm trying to create my own command-line IntelliJ tool, using InspectionApplication as a model.  (Briefly: I want to run the error highlighters on my whole project and collect the results.) I can't get it to work because I'm getting IndexNotReady exceptions. I think probably this is happening because it's still in the process of loading the (large) project.

How do I get my Application to wait until the Index is ready before it starts trying to run the code that wants to read it?

 

0
5 comments

Hi Richard,

please attach the stacktrace.

Thanks,

Anna

0

Here you go, Anna.  I think something may be going wrong fairly early, because I get an IntelliJ window coming up, whereas inspect suppresses that when it runs. Sometimes it's hard to succeed just by copying code...is there documentation that I have missed on how to write a command-line tool?

Thanks,

-- Rich

-----------
Indexing started at:
java.lang.Throwable
at com.intellij.openapi.project.DumbServiceImpl.scheduleCacheUpdate(DumbServiceImpl.java:160)
at com.intellij.openapi.project.DumbServiceImpl.queueTask(DumbServiceImpl.java:85)
at com.intellij.openapi.project.impl.ProjectManagerImpl$4.run(ProjectManagerImpl.java:356)
at com.intellij.openapi.project.DumbPermissionServiceImpl.allowStartingDumbModeInside(DumbPermissionServiceImpl.java:35)
at com.intellij.openapi.project.DumbService.allowStartingDumbModeInside(DumbService.java:281)
at com.intellij.openapi.project.impl.ProjectManagerImpl.openProject(ProjectManagerImpl.java:353)
at com.intellij.openapi.project.impl.ProjectManagerImpl.loadAndOpenProject(ProjectManagerImpl.java:467)
at com.intellij.ide.impl.ProjectUtil.openProject(ProjectUtil.java:184)
at com.intellij.ide.impl.ProjectUtil.openOrImport(ProjectUtil.java:116)
at com.guidewire.studio.tools.verifier.VerifierApplication.run(VerifierApplication.java:106)
at com.guidewire.studio.tools.verifier.VerifierApplication.lambda$startup$0(VerifierApplication.java:74)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:946)
at com.guidewire.studio.tools.verifier.VerifierApplication.startup(VerifierApplication.java:67)
at com.guidewire.studio.tools.verifier.VerifierMain.main(VerifierMain.java:81)
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:197)
at com.intellij.idea.MainImpl$1$1$1.run(MainImpl.java:52)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:361)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
com.intellij.openapi.project.IndexNotReadyException: Please change caller according to com.intellij.openapi.project.IndexNotReadyException documentation
at com.intellij.util.indexing.FileBasedIndexImpl.handleDumbMode(FileBasedIndexImpl.java:871)
at com.intellij.util.indexing.FileBasedIndexImpl.ensureUpToDate(FileBasedIndexImpl.java:818)
at com.intellij.util.indexing.FileBasedIndexImpl.processExceptions(FileBasedIndexImpl.java:933)
at com.intellij.util.indexing.FileBasedIndexImpl.processValuesImpl(FileBasedIndexImpl.java:1010)
at com.intellij.util.indexing.FileBasedIndexImpl.getContainingFiles(FileBasedIndexImpl.java:894)
at com.guidewire.studio.pcf.PCFFileIndex.getVirtualFilesWithSyntaxErrors(PCFFileIndex.java:254)
at com.guidewire.studio.pcf.PCFFileIndex.hasSyntaxError(PCFFileIndex.java:258)
at com.guidewire.studio.pcf.PCFIdeaSourceMap.lambda$getParseErrorsForFile$17(PCFIdeaSourceMap.java:248)
at com.guidewire.studio.util.IndexUtil.runReadActionInSmartMode(IndexUtil.java:13)
at com.guidewire.studio.pcf.PCFIdeaSourceMap.runReadActionInSmartMode(PCFIdeaSourceMap.java:62)
at com.guidewire.studio.pcf.PCFIdeaSourceMap.getParseErrorsForFile(PCFIdeaSourceMap.java:247)
at com.guidewire.studio.pcf.validator.PCFVerificationHighlightingPass.collectInformationForSyntaxErrors(PCFVerificationHighlightingPass.java:110)
at com.guidewire.studio.pcf.validator.PCFVerificationHighlightingPass.collectInformation(PCFVerificationHighlightingPass.java:91)
at com.guidewire.studio.pcf.validator.PCFFileVerifier.runMainPasses(PCFFileVerifier.java:101)
at com.guidewire.studio.pcf.validator.PCFFileVerifier.lambda$doHighlighting$2(PCFFileVerifier.java:90)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:446)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.guidewire.studio.pcf.validator.PCFFileVerifier.doHighlighting(PCFFileVerifier.java:88)
at com.guidewire.studio.pcf.validator.PCFFileVerifier.verifyFile(PCFFileVerifier.java:70)
at com.guidewire.studio.tools.verifier.AbstractFileVerifier$1.run(AbstractFileVerifier.java:48)
at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
at com.intellij.openapi.application.ReadAction$1.compute(ReadAction.java:29)
at com.intellij.openapi.application.ReadAction$1.compute(ReadAction.java:26)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:963)
at com.intellij.openapi.application.ReadAction.execute(ReadAction.java:26)
at com.guidewire.studio.tools.verifier.AbstractFileVerifier.verify(AbstractFileVerifier.java:50)
at com.guidewire.studio.tools.verifier.VerifierApplication.lambda$null$3(VerifierApplication.java:156)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at com.guidewire.studio.tools.verifier.VerifierApplication.lambda$null$4(VerifierApplication.java:156)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:446)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:443)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.guidewire.studio.tools.verifier.VerifierApplication.lambda$null$5(VerifierApplication.java:155)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:946)
at com.guidewire.studio.tools.verifier.VerifierApplication.lambda$run$6(VerifierApplication.java:145)
at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:142)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:446)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:127)
at com.guidewire.studio.tools.verifier.VerifierApplication.run(VerifierApplication.java:144)
at com.guidewire.studio.tools.verifier.VerifierApplication.lambda$startup$0(VerifierApplication.java:74)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:946)
at com.guidewire.studio.tools.verifier.VerifierApplication.startup(VerifierApplication.java:67)
at com.guidewire.studio.tools.verifier.VerifierMain.main(VerifierMain.java:81)
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:197)
at com.intellij.idea.MainImpl$1$1$1.run(MainImpl.java:52)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:361)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

0

It looks to me as though running "headless" might solve the problem for me...it's doing much better now that I forced it to headless with -Djava.awt.headless=true

I see that IntelliJ automatically forces headless operation if you are running one of its command-line applications, but not if it's something else.  Although perhaps if I name my command <something>-inspect it would have worked...see below.

Probably I can work with this, but I wonder if Main.isHeadless() could figure this out.

private static boolean isHeadless(String[] args) {
if (Boolean.valueOf(System.getProperty(AWT_HEADLESS))) {
return true;
}

if (args.length == 0) {
return false;
}

String firstArg = args[0];
return Comparing.strEqual(firstArg, "ant") ||
Comparing.strEqual(firstArg, "duplocate") ||
Comparing.strEqual(firstArg, "traverseUI") ||
(firstArg.length() < 20 && firstArg.endsWith("inspect"));
}
0

Unfortunately, creating one's own command-line tools is harder than it would seem :( Are you developing a plugin, or you have your own distribution?

For a quick workaround, please try DumbService#runWhenSmart, it should be invoked on Swing thread after indexing.

0

Thanks, Peter.  It seems to have run successfully, now that I have forced it to run headless.  But I will go look at what that method does, and if I get into trouble hopefully I'll remember it.

I am a plugin developer. We have custom plugins which are used to develop and configure our commercial software product. What I am trying to do was run the error highlighter from one of the custom plugins and collect the diagnostics in a file.

0

Please sign in to leave a comment.