Implementing Autocompletion by using indexed values

Answered

Hello everyone,

I have an issue with my plugin. I have implement a ReferenceProvider for autocompletion and reference check in XML Files. 
My problem is that the references and autocompletion does not work. In order to make the loading of the ids from other files efficent I try to load the required files by indexing them. Therefore I am also creating a GlobalSearchScope for the directories where I am trying to locate the references.

Via the method `FileBasedIndex.getInstance().getContainingFiles(...)` I am trying to find the indexed files by given key. 

But for some reason I don't understand why my index key has no values. But it should have some.

But when I invalidate the cache and start intellij again, I can see that the Index is working.After starting the project later it does not work until I invalidate the cache again and restart intellij

Here is a sample of my code and the test project for the plugin.
Upload id: 2022_10_20_5Y4NEx5PTHq4BspJATxitz (files: plugin_code.zip, completionTest.zip)

0
13 comments

Hi Pascal,

I opened your project, and I'm getting NullPointerExceptions at the IDE start when the index is being built:

2022-10-21 14:10:59,571 [  57280]  ERROR - stic.BrokenIndexingDiagnostics - Failed to build index 'de.adesso.fire.rule_base.mapping' for file file:///Users/karol.lewandowski/Downloads/completionTest/rule-base/mappings/mapping.xml (id = 4862) (file type = XML) [Plugin: com.example.demo] 
Caused by: com.intellij.util.indexing.impl.MapReduceIndexMappingException: java.lang.NullPointerException

com.intellij.diagnostic.PluginException: Failed to build index 'de.adesso.fire.rule_base.mapping' for file file:///Users/karol.lewandowski/Downloads/completionTest/rule-base/mappings/mapping.xml (id = 4862) (file type = XML) [Plugin: com.example.demo]
    at com.intellij.ide.plugins.PluginManagerCore.createPluginException(PluginManagerCore.java:274)
Caused by: java.lang.NullPointerException

    at com.intellij.diagnostic.PluginProblemReporterImpl.createPluginExceptionByClass(PluginProblemReporterImpl.java:12)
    at com.intellij.diagnostic.PluginException.createByClass(PluginException.java:91)
    at com.intellij.util.indexing.diagnostic.BrokenIndexingDiagnostics$DefaultListener.onFileIndexMappingFailed(BrokenIndexingDiagnostics.kt:47)
    at com.intellij.util.indexing.FileBasedIndexImpl.updateSingleIndex(FileBasedIndexImpl.java:1530)
    at com.intellij.util.indexing.FileBasedIndexImpl.lambda$doIndexFileContent$23(FileBasedIndexImpl.java:1394)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.freezeFileTypeTemporarilyIn(FileTypeManagerImpl.java:648)
    at com.intellij.util.indexing.FileBasedIndexImpl.doIndexFileContent(FileBasedIndexImpl.java:1361)
    at com.intellij.util.indexing.FileBasedIndexImpl.indexFileContent(FileBasedIndexImpl.java:1315)
    at com.intellij.util.indexing.contentQueue.IndexUpdateRunner.lambda$indexOneFileOfJob$5(IndexUpdateRunner.java:267)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.insideReadAction(NonBlockingReadActionImpl.java:521)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$attemptComputation$3(NonBlockingReadActionImpl.java:486)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1078)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runInReadActionWithWriteActionPriority$0(ProgressIndicatorUtils.java:78)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:161)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runWithWriteActionPriority$1(ProgressIndicatorUtils.java:118)
    at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:57)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:183)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:705)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:647)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:63)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:170)
    at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:57)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runWithWriteActionPriority(ProgressIndicatorUtils.java:115)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(ProgressIndicatorUtils.java:78)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.attemptComputation(NonBlockingReadActionImpl.java:486)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.executeSynchronously(NonBlockingReadActionImpl.java:421)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl.executeSynchronously(NonBlockingReadActionImpl.java:186)
    at com.intellij.util.indexing.contentQueue.IndexUpdateRunner.indexOneFileOfJob(IndexUpdateRunner.java:270)
    at com.intellij.util.indexing.contentQueue.IndexUpdateRunner.lambda$indexJobsFairly$4(IndexUpdateRunner.java:210)
    at com.intellij.openapi.progress.impl.ProgressSuspender.executeNonSuspendableSection(ProgressSuspender.java:83)
    at com.intellij.util.indexing.contentQueue.IndexUpdateRunner.indexJobsFairly(IndexUpdateRunner.java:213)
    at com.intellij.util.indexing.contentQueue.IndexUpdateRunner.lambda$doIndexFiles$3(IndexUpdateRunner.java:147)
    at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:216)
    at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:27)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.execute(BoundedTaskExecutor.java:195)
    at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:213)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:184)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.intellij.util.indexing.impl.MapReduceIndexMappingException: java.lang.NullPointerException
    at com.intellij.util.indexing.impl.MapReduceIndex.mapInputAndPrepareUpdate(MapReduceIndex.java:272)
    at com.intellij.indexing.composite.CompositeInvertedIndexBase.updateBaseIndex(CompositeInvertedIndexBase.java:232)
    at com.intellij.indexing.composite.CompositeInvertedIndexBase.mapInputAndPrepareUpdate(CompositeInvertedIndexBase.java:55)
    at com.intellij.indexing.composite.CompositeInvertedIndexBase.mapInputAndPrepareUpdate(CompositeInvertedIndexBase.java:26)
    at com.intellij.util.indexing.FileBasedIndexImpl.updateSingleIndex(FileBasedIndexImpl.java:1520)
    ... 40 more
Caused by: java.lang.NullPointerException
    at com.example.demo.index.indexer.IdIndexer.map(IdIndexer.java:65)
    at com.example.demo.index.indexer.IdIndexer.map(IdIndexer.java:19)
    at com.intellij.util.indexing.impl.MapReduceIndex.mapByIndexer(MapReduceIndex.java:328)
    at com.intellij.util.indexing.impl.MapReduceIndex.mapInput(MapReduceIndex.java:318)
    at com.intellij.util.indexing.impl.storage.VfsAwareMapReduceIndex.mapInput(VfsAwareMapReduceIndex.java:182)
    at com.intellij.util.indexing.impl.storage.VfsAwareMapReduceIndex.mapInput(VfsAwareMapReduceIndex.java:47)
    at com.intellij.util.indexing.impl.MapReduceIndex.mapInputAndPrepareUpdate(MapReduceIndex.java:263)
    ... 44 more

It may be the cause, so please fix it (I guess simple null checks should do the job) and check if it solves the issues.

0

Thats confusing because I do not have this kind of NullpointerException.
But I found some other issues which I uploaded.
Here the updated Project Upload id: 2022_10_21_APnaheusqYRJsyRGFz5WPA (file: plugin_code.zip) 

Did you start the plugin via "Run Plugin" or did you build a plugin and install it?

0

It seems that NPE is thrown because `rule-base/mappings/mapping.xml` root tag doesn't have `noNamespaceSchemaLocation` attribute (if I understand the code correctly). It is thrown only on the first run or after invalidating caches.

I used "Run Plugin".

Please also clarify how to reproduce the issue. Which file should I open, and what should I do to reproduce it?

0

Hello Karol,
thanks for your answer I did not strip enough from the old code. I will fix this and upload a new version of the code. 
To reproduce the error you just need to start the project and go into the file `rule-base/mappings/mapping.xml` there you should see a lot of errors for all XML Attributes `parameter` and `variable`. You also should not have any  suggestions for completion. 

You also should see in the file `objects/assemblies/some_object.xml` should have genereate the index for reference after the change but not in the `mapping.xml` file. 
See the image:
 

0

Here the updated version of my code. I hope I have strip everything which is unnecessary from the code. 
Upload id: 2022_10_21_279GtaTzKRt7s67tDNMtL7 (files: test_plugin_project.zip, plugin_code_fixed.zip)

0

Your com.example.demo.index.MasterIdToConfigurationIdKeyValue doesn’t implement equals() and hashCode() and entries cannot be found in the index. I generated the methods, and all work correctly.

0

Hello Karol,

I do not think that the equals() and hashCode() will solve my Problem. In my actual Project I am using the @Value Annotation from Lombok. But nevertheless I did generate the equals() and hashCode() and it doesn't change anything as you can see.

It only works when I clean the cash before but I want that it works all the time. Did I forget any trigger or something?

0

Hi,

You are right - it didn't fix the issue. I must have accidentally cleaned the cache when closing the project.

I still didn't find the issue, and looking at the code, I couldn't spot anything suspicious. I'll try to get back to it later this week.

In the meantime, I suggest debugging the serialization code. Maybe there is an issue with storing values on disk or reading them back.

EDIT: I noticed that you override com.intellij.util.indexing.FileBasedIndexExtension#traceKeyHashToVirtualFileMapping() to return true which affects the index content after re-runnig the application. I asked the responsible developer about it and will get back to you when I know more.

0

Hi Pascal,

To keep you updated: Initially, it looks like a bug, but the developer who is familiar with this part of indexing is off and will be back the next week.

Please be patient, and sorry for the inconvenience.

0

Hi Karol,

Thanks for the information. I will wait patiently for a fix or more information regarding the indexing. 
Do you have a ticket for me were I can track the state of this issue?

0

Hi Pascal,

I didn't create an issue yet as it's not confirmed that it is a bug. Let's wait for the confirmation.

0

Hello Karol,

thank you! I will follow it patiently!

0

Please sign in to leave a comment.