Community
Participate
Working Groups
Build ID: I20080502-0100 Steps To Reproduce: My code perform searches for Annotation type references (for uses of annotations in source files) after certain Java Element deltas from JDT reconcile events in a background job (potentially, multiple jobs). With a new workspace and containers that have many jars that haven't been indexed yet, I periodically get NPE thrown with the following stack: java.lang.NullPointerException at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.selectIndexes(JavaSearchParticipant.java:107) at org.eclipse.jdt.internal.core.search.PatternSearchJob.getIndexes(PatternSearchJob.java:79) at org.eclipse.jdt.internal.core.search.PatternSearchJob.ensureReadyToRun(PatternSearchJob.java:50) at org.eclipse.jdt.internal.core.search.processing.JobManager.performConcurrentJob(JobManager.java:174) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:200) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:500) at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551) at com.ibm.etools.annotations.core.internal.search.JavaSearchUtils.findAnnotations(JavaSearchUtils.java:462) at Looking like it stems from the following: java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.util.SimpleLookupTable.get(SimpleLookupTable.java:68) at org.eclipse.jdt.internal.core.search.indexing.IndexManager.getIndex(IndexManager.java:201) at org.eclipse.jdt.internal.core.search.indexing.IndexManager.getIndexes(IndexManager.java:299) at org.eclipse.jdt.internal.core.search.PatternSearchJob.getIndexes(PatternSearchJob.java:81) at org.eclipse.jdt.internal.core.search.PatternSearchJob.ensureReadyToRun(PatternSearchJob.java:50) at org.eclipse.jdt.internal.core.search.processing.JobManager.performConcurrentJob(JobManager.java:174) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:200) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:500) at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551) at Is this a harmful exception? More information:
Looking at the code, we lazy initialize the field that is null just before using it. So the NPE can only occurs if the same JavaSearchParticipant is used in several threads. From JDT/Core code, it looks like we create a new one per search invocation. So it must come from the client. Ernest, are you passing a search participant to SearchEngine.search(...)? If so, are you reusing the same participant?
Yes, I'm using the default search participant and reusing it in the jobs. Is this incorrect usage?
(In reply to comment #2) > Yes, I'm using the default search participant and reusing it in the jobs. Is > this incorrect usage? No, it is not an incorrect usage. However we did not anticipate this usage. A workaround for you would be to call 'SearchEngine.getDefaultParticipant()' and pass it to each search query instead of reusing the SearchParticipant instance. Not this should have no effect on performance.
I meant "Note that this should have no effect on performance."
Created attachment 126483 [details] Proposed patch
Released for 3.5M6 in HEAD stream.
Verified for 3.5M6 with build I20090309-0100