Bug 233356 - [search] NPE in org.eclipse.jdt.internal.compiler.util.SimpleLookupTable.get()
Summary: [search] NPE in org.eclipse.jdt.internal.compiler.util.SimpleLookupTable.get()
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-21 18:15 EDT by Ernest Mah CLA
Modified: 2009-03-10 07:20 EDT (History)
3 users (show)

See Also:


Attachments
Proposed patch (2.03 KB, patch)
2009-02-23 12:44 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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