Strange exception "The reported element is not from the file the inspection was invoked for"

Answered
While running an inspection I sometimes get the following error message: Reported element PyFile:ABC.py is not from the file 'C:/dev/Project/CDE.txt' the inspection Was invoked for. The inspection uses regular expressions to detect issues and returns a list of Problem descriptors. So there is no cross-file-checking. Is there any way to avoid this issue or at least to catch this error? com.intellij.diagnostic.PluginException: Reported element PyFile:ABC.py is not from the file 'C:/dev/Project/CDE.txt' the inspection 'CustomInspectionsInspector' (class com.pyfips.intellij.custominspections.CustomInspectionsInspector) was invoked for. Message: 'Some String given in ProblemDescriptor'. Element containing file: PyFile:ABC.py Inspection invoked for file: locale file [Plugin: com.pyfips.intellij.custominspections] at com.intellij.ide.plugins.PluginManagerCore.createPluginException(PluginManagerCore.java:447) at com.intellij.diagnostic.PluginProblemReporterImpl.createPluginExceptionByClass(PluginProblemReporterImpl.java:12) at com.intellij.diagnostic.PluginException.createByClass(PluginException.java:58) at com.intellij.diagnostic.PluginException.logPluginError(PluginException.java:75) at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.createHighlightsForDescriptor(LocalInspectionsPass.java:556) at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.addHighlightsFromResults(LocalInspectionsPass.java:487) at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.inspect(LocalInspectionsPass.java:202) at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.collectInformationWithProgress(LocalInspectionsPass.java:115) at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:84) at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:52) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$null$1(PassExecutorService.java:442) at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1106) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:435) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:627) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:572) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:434) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:410) at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:168) at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:168) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:408) at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:171) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
0
4 comments

com.pyfips.intellij.custominspections.CustomInspectionsInspector is creating ProblemDescriptor referring to elements which are not located within the currently inspected file. How could we improve the exception message?

0

Hello Yann,
The exception message is fine. But looking at the code, the inspection never touches any other file than the one it gets from the PsiFile. I only could imagine three ways how the exception can occur:
1) The inspection is invoked when PsiFile.GetText() is empty. Which would be wrong because neither of the files are empty.
2) The related Psifile object changes while processing the ProblemDescriptor.checkFile function.
3) the hashes of the text of two completely different files are the same

The problem is that this exception only occurs sometimes. So I thought of a race condition but maybe I am wrong.

The corresponding code is here https://gitlab.com/pyfips/custominspections/-/blob/master/src/com/pyfips/intellij/custominspections/CustomInspectionsInspector.java

0

What are you trying to cache here with lastComparedTextHash etc.? The IDE will invoke the inspection only if necessary.

Definitely sharing a mutable collection https://gitlab.com/pyfips/custominspections/-/blob/master/src/com/pyfips/intellij/custominspections/CustomInspectionsInspector.java#L27 is dangerous, please convert to local variable.

0

While testing with the debugger, the inspection was often invoked twice. However, it may be because I often do save explicitly. Since the output of the same text will always be the same, I thought I could do a performance optimization here.
I will convert it to a local variable and see if the error message still occurs.
Thank you!

0

Please sign in to leave a comment.