Bug 233356

Summary: [search] NPE in org.eclipse.jdt.internal.compiler.util.SimpleLookupTable.get()
Product: [Eclipse Project] JDT Reporter: Ernest Mah <ernest>
Component: CoreAssignee: Frederic Fusier <frederic_fusier>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, jerome_lanneluc, Olivier_Thomann
Version: 3.4   
Target Milestone: 3.5 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed patch none

Description Ernest Mah CLA 2008-05-21 18:15:22 EDT
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:
Comment 1 Jerome Lanneluc CLA 2008-05-22 05:06:00 EDT
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?
Comment 2 Ernest Mah CLA 2008-05-22 10:30:10 EDT
Yes, I'm using the default search participant and reusing it in the jobs.  Is this incorrect usage?
Comment 3 Jerome Lanneluc CLA 2008-05-22 10:39:53 EDT
(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.
Comment 4 Jerome Lanneluc CLA 2008-05-22 10:40:28 EDT
I meant "Note that this should have no effect on performance."
Comment 5 Frederic Fusier CLA 2009-02-23 12:44:14 EST
Created attachment 126483 [details]
Proposed patch
Comment 6 Frederic Fusier CLA 2009-02-23 12:49:49 EST
Released for 3.5M6 in HEAD stream.
Comment 7 Jay Arthanareeswaran CLA 2009-03-10 07:06:17 EDT
Verified for 3.5M6 with build I20090309-0100