Bug 158526 - [search] NPE in JavaSearchScope.addEnclosingProjectOrJar(..)
Summary: [search] NPE in JavaSearchScope.addEnclosingProjectOrJar(..)
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 211485 216939 220519 223124 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-09-25 05:36 EDT by Markus Keller CLA
Modified: 2008-04-29 04:21 EDT (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2006-09-25 05:36:14 EDT
I20060922-0010

- new workspace
- open Plug-ins view, select all plugins, context menu > Add to Java Search
- Run > Debug...
- create a new 'Remote Java Application' launch configuration and select 'External Plug-in Libraries' as project; save, but do not debug
- go to Debug perspective, Breakpoints view, and press 'Add Java Breakpoint' button

java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:350)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:479)
at org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog.run(ProgressMonitorJobsDialog.java:265)
at org.eclipse.ui.internal.progress.ProgressManager$3.run(ProgressManager.java:890)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:925)
at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:900)
at org.eclipse.ui.internal.progress.ProgressManager.run(ProgressManager.java:1108)
at org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog2.ensureConsistency(TypeSelectionDialog2.java:341)
at org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog2.open(TypeSelectionDialog2.java:208)
at org.eclipse.jdt.internal.debug.ui.breakpoints.AddExceptionAction.run(AddExceptionAction.java:85)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:254)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:539)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:488)
at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:441)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3390)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3009)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:419)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:95)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:348)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:165)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:341)
at org.eclipse.core.launcher.Main.basicRun(Main.java:285)
at org.eclipse.core.launcher.Main.run(Main.java:987)
at org.eclipse.core.launcher.Main.main(Main.java:962)
Caused by: java.lang.NullPointerException
at org.eclipse.jdt.internal.core.search.JavaSearchScope.addEnclosingProjectOrJar(JavaSearchScope.java:60)
at org.eclipse.jdt.internal.core.search.JavaSearchScope.add(JavaSearchScope.java:141)
at org.eclipse.jdt.internal.core.search.JavaWorkspaceScope.initialize(JavaWorkspaceScope.java:84)
at org.eclipse.jdt.internal.core.search.JavaWorkspaceScope.enclosingProjectsAndJars(JavaWorkspaceScope.java:63)
at org.eclipse.jdt.internal.core.search.IndexSelector.initializeIndexLocations(IndexSelector.java:123)
at org.eclipse.jdt.internal.core.search.IndexSelector.getIndexLocations(IndexSelector.java:204)
at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.selectIndexes(JavaSearchParticipant.java:112)
at org.eclipse.jdt.internal.core.search.PatternSearchJob.getIndexes(PatternSearchJob.java:80)
at org.eclipse.jdt.internal.core.search.PatternSearchJob.ensureReadyToRun(PatternSearchJob.java:51)
at org.eclipse.jdt.internal.core.search.processing.JobManager.performConcurrentJob(JobManager.java:177)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.searchAllTypeNames(BasicSearchEngine.java:770)
at org.eclipse.jdt.core.search.SearchEngine.searchAllTypeNames(SearchEngine.java:603)
at org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog2$1$ConsistencyRunnable.refreshSearchIndices(TypeSelectionDialog2.java:320)
at org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog2$1$ConsistencyRunnable.run(TypeSelectionDialog2.java:306)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Comment 1 Markus Keller CLA 2006-09-25 05:43:15 EDT
If you wait a bit (until indexing is done?) before pressing the 'Add Java Breakpoint' button, the following exception is thrown:

java.lang.ArrayIndexOutOfBoundsException: 24
        at org.eclipse.jdt.internal.core.search.JavaSearchScope.addEnclosingProjectOrJar(JavaSearchScope.java:60)
        at org.eclipse.jdt.internal.core.search.JavaSearchScope.add(JavaSearchScope.java:141)
        at org.eclipse.jdt.internal.core.search.JavaWorkspaceScope.initialize(JavaWorkspaceScope.java:84)
        at org.eclipse.jdt.internal.core.search.JavaWorkspaceScope.enclosingProjectsAndJars(JavaWorkspaceScope.java:63)
        at org.eclipse.jdt.internal.core.search.IndexSelector.initializeIndexLocations(IndexSelector.java:123)
        at org.eclipse.jdt.internal.core.search.IndexSelector.getIndexLocations(IndexSelector.java:204)
        at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.selectIndexes(JavaSearchParticipant.java:112)
        at org.eclipse.jdt.internal.core.search.PatternSearchJob.getIndexes(PatternSearchJob.java:80)
        at org.eclipse.jdt.internal.core.search.PatternSearchJob.ensureReadyToRun(PatternSearchJob.java:51)
        at org.eclipse.jdt.internal.core.search.processing.JobManager.performConcurrentJob(JobManager.java:177)
        at org.eclipse.jdt.internal.core.search.BasicSearchEngine.searchAllTypeNames(BasicSearchEngine.java:770)
        at org.eclipse.jdt.core.search.SearchEngine.searchAllTypeNames(SearchEngine.java:680)
        at org.eclipse.jdt.internal.ui.dialogs.TypeInfoViewer$SearchEngineJob.getSearchResult(TypeInfoViewer.java:649)
        at org.eclipse.jdt.internal.ui.dialogs.TypeInfoViewer$AbstractSearchJob.internalRun(TypeInfoViewer.java:556)
        at org.eclipse.jdt.internal.ui.dialogs.TypeInfoViewer$AbstractSearchJob.doRun(TypeInfoViewer.java:503)
        at org.eclipse.jdt.internal.ui.dialogs.TypeInfoViewer$AbstractJob.run(TypeInfoViewer.java:469)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:58)
Comment 2 Frederic Fusier CLA 2006-09-25 12:56:35 EDT
I guess you talked about 'Add Java Exception Breakpoint' as I cannot find any 'Add Java Breakpoint' button. However, I cannot reproduce the exception, even waiting a long time... I did a test using 3.3 M2 runtime session or in self-hosting environment. I also used both VM 1.4.2 and 1.5.0, all these tests succeeded.

Any other hints to help me to reproduce?
Comment 3 Markus Keller CLA 2006-09-26 10:21:09 EDT
Yes, I meant 'Add Java Exception Breakpoint'.

I could also reproduce with steps from comment 0 in a runtime workspace running on JDK 1.5.0_08. Have you tried reproducing with a fresh install and a new workspace, starting with 'eclipse.exe -data newWorkspace -consolelog'?
Comment 4 Frederic Fusier CLA 2006-09-26 10:40:44 EDT
(In reply to comment #3)
> Yes, I meant 'Add Java Exception Breakpoint'.
> 
> I could also reproduce with steps from comment 0 in a runtime workspace running
> on JDK 1.5.0_08. Have you tried reproducing with a fresh install and a new
> workspace, starting with 'eclipse.exe -data newWorkspace -consolelog'?
> 
Yes, I did this test with same config: JDK 1.5.0_08 + 3.3 M2 fresh install + new wksp + run:
eclipse.exe -data d:\tmp\wksp -consoleLog -vm d:\a\JDKs\sun\1.5.0\jre\bin\java
+ comment 0 steps
And I didn't get any exception in console...!?

Could you reproduce it on an other box?

Comment 5 Markus Keller CLA 2006-09-26 12:44:51 EDT
I could also reproduce on our Linux-GTK box (dual core, like my machine).
I could *not* reproduce on Martin's single-core machine.

Refined steps:
- new workspace
- close Welcome view
- Alt+Shift+Q, Q
- open Plug-ins view
--- the following steps should be executed without breaks: ---
- Ctrl+A
- context menu > Add to Java Search
- main menu Run > Debug...
- doubleclick 'Remote Java Application'
- click 'Browse', click 'OK'
- click 'Close', click 'Yes'
- open Debug perspective
- click on tab of 'Breakpoints' view
- click 'Add Java Exception Breakpoint' button

I did not manage to get the trace from comment 0 any more. When I execute the steps with normal speed, I always get comment 1 now. When I waited very long between steps (to write up this list), I did not get any log entries any more.
Comment 6 Markus Keller CLA 2007-02-23 08:57:12 EST
Steps to reproduce the NPE in I20070222-0951 (3.3M5a candidate):
- new workspace
- create new Java project "J"
- import org.eclipse.pde.ui and all required plug-ins as binary
- while the (non-modal) progress dialog is up, select "J"
- open New Class wizard
- repeat the following around the time when the plug-in import completes:
  - click Browse... for superclass
  - click Cancel

eclipse.buildId=I20070222-0951
java.version=1.5.0_11
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=de_CH
Framework arguments:  -showlocation
Command-line arguments:  -data cl1 -clean -consolelog -console -showlocation

Error
Fri Feb 23 14:50:26 CET 2007
An internal error occurred during: "Items filtering".

java.lang.NullPointerException
at org.eclipse.jdt.internal.core.search.JavaSearchScope.addEnclosingProjectOrJar(JavaSearchScope.java:77)
at org.eclipse.jdt.internal.core.search.JavaSearchScope.add(JavaSearchScope.java:145)
at org.eclipse.jdt.internal.core.search.JavaWorkspaceScope.initialize(JavaWorkspaceScope.java:84)
at org.eclipse.jdt.internal.core.search.JavaWorkspaceScope.enclosingProjectsAndJars(JavaWorkspaceScope.java:63)
at org.eclipse.jdt.internal.core.search.IndexSelector.initializeIndexLocations(IndexSelector.java:122)
at org.eclipse.jdt.internal.core.search.IndexSelector.getIndexLocations(IndexSelector.java:203)
at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.selectIndexes(JavaSearchParticipant.java:112)
at org.eclipse.jdt.internal.core.search.PatternSearchJob.getIndexes(PatternSearchJob.java:80)
at org.eclipse.jdt.internal.core.search.PatternSearchJob.ensureReadyToRun(PatternSearchJob.java:51)
at org.eclipse.jdt.internal.core.search.processing.JobManager.performConcurrentJob(JobManager.java:177)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.searchAllTypeNames(BasicSearchEngine.java:777)
at org.eclipse.jdt.core.search.SearchEngine.searchAllTypeNames(SearchEngine.java:780)
at org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog.fillContentProvider(FilteredTypesSelectionDialog.java:467)
at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$FilterJob.filterContent(FilteredItemsSelectionDialog.java:2055)
at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$AbstractFilterJob.internalRun(FilteredItemsSelectionDialog.java:1940)
at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$AbstractFilterJob.doRun(FilteredItemsSelectionDialog.java:1901)
at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$AbstractFilterJob.run(FilteredItemsSelectionDialog.java:1881)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:58)
Comment 7 Frederic Fusier CLA 2007-02-23 09:50:40 EST
Unfortunately, strictly following your scenario, I'm not again able to reproduce... :-(

Looking at the code, this strongly looks like a multi-thread issue. I'm pretty sure that synchronizing the addEnclosingPorjectOrJar method would solve the problem:
private synchronized void addEnclosingProjectOrJar(IPath path) {
...
}

If you have some times to try this fix, please let me know if my assumption is correct or not.

TIA
Comment 8 Markus Keller CLA 2007-02-23 10:31:17 EST
Darn! I got the NPE by accident and then I could reproduce it a few times. But now, don't get it any more, however hard I try :-(.
I'll look at it again if I get the NPE again.
Comment 9 Frederic Fusier CLA 2008-01-08 07:57:21 EST
I guess we can close this bug as WORKSFORME now. Please reopen if you get it again, thanks
Comment 10 David Audel CLA 2008-02-04 12:08:32 EST
I got another exception when trying to reproduce the bug with build I20080204-0010.
Unfortunately i am unable to reproduce it another time.

The exception was:
java.lang.ArrayIndexOutOfBoundsException: 45
	at org.eclipse.jdt.internal.core.search.JavaSearchScope.addEnclosingProjectOrJar(JavaSearchScope.java:77)
	at org.eclipse.jdt.internal.core.search.JavaSearchScope.add(JavaSearchScope.java:177)
	at org.eclipse.jdt.internal.core.search.JavaWorkspaceScope.initialize(JavaWorkspaceScope.java:84)
	at org.eclipse.jdt.internal.core.search.JavaWorkspaceScope.enclosingProjectsAndJars(JavaWorkspaceScope.java:63)
	at org.eclipse.jdt.internal.core.search.IndexSelector.initializeIndexLocations(IndexSelector.java:120)
	at org.eclipse.jdt.internal.core.search.IndexSelector.getIndexLocations(IndexSelector.java:201)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.selectIndexes(JavaSearchParticipant.java:107)
	at org.eclipse.jdt.internal.core.search.PatternSearchJob.getIndexes(PatternSearchJob.java:80)
	at org.eclipse.jdt.internal.core.search.PatternSearchJob.ensureReadyToRun(PatternSearchJob.java:51)
	at org.eclipse.jdt.internal.core.search.processing.JobManager.performConcurrentJob(JobManager.java:174)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.searchAllTypeNames(BasicSearchEngine.java:784)
	at org.eclipse.jdt.core.search.SearchEngine.searchAllTypeNames(SearchEngine.java:712)
	at org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog$ConsistencyRunnable.refreshSearchIndices(FilteredTypesSelectionDialog.java:703)
	at org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog$ConsistencyRunnable.run(FilteredTypesSelectionDialog.java:689)
	at org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog.reloadCache(FilteredTypesSelectionDialog.java:729)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$RefreshCacheJob.run(FilteredItemsSelectionDialog.java:1476)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)


I reopen the bug.
Comment 11 Frederic Fusier CLA 2008-02-04 12:17:51 EST
*** Bug 216939 has been marked as a duplicate of this bug. ***
Comment 12 Frederic Fusier CLA 2008-02-04 12:19:35 EST
It seems to be a potential problem from the beginning with the initialization
of the JavaWorkspaceScope global variable stored in the JavaModelManager.

I cannot see any synchronization which would make it thread safe and I guess
that 2 threads trying to get a java workspace scope concurrently on the first
place may fall into such problematic situation...
Comment 13 Frederic Fusier CLA 2008-02-27 05:10:18 EST
*** Bug 220519 has been marked as a duplicate of this bug. ***
Comment 14 Frederic Fusier CLA 2008-02-27 05:11:25 EST
I think this must be fixed for 3.4
Comment 15 Frederic Fusier CLA 2008-02-29 04:44:34 EST
Should be fixed by the patch proposed on bug 182738:
https://bugs.eclipse.org/bugs/attachment.cgi?id=91131
Comment 16 Frederic Fusier CLA 2008-02-29 12:34:15 EST
See new proposed patch on bug 182738:
https://bugs.eclipse.org/bugs/attachment.cgi?id=91211
Comment 17 Frederic Fusier CLA 2008-03-20 06:43:26 EDT
*** Bug 211485 has been marked as a duplicate of this bug. ***
Comment 18 Frederic Fusier CLA 2008-03-20 06:43:47 EDT
*** Bug 223124 has been marked as a duplicate of this bug. ***
Comment 19 Frederic Fusier CLA 2008-04-17 13:21:30 EDT
Jerome,
I hoped that this one could be fixed with the patch I proposed on bug 182738. Please reassign it to me if you think this assumption was not correct.
Thanks
Comment 20 Jerome Lanneluc CLA 2008-04-23 07:21:53 EDT
Fix for bug 182738 actually fixed this problem. The enclosingProjectsAndJars() method is now thread safe (it computes the list in a local variable, and it is assigned only at the end of the method).

Marking this bug as fixed for 3.4M7
Comment 21 Maxime Daniel CLA 2008-04-29 04:21:42 EDT
Verified for 3.4 M7 by code inspection of v_856.