Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 228297

Summary: Add src workspace to a target workspace fails
Product: [Eclipse Project] PDE Reporter: Ian Bull <irbull>
Component: UIAssignee: Curtis Windatt <curtis.windatt.public>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: caniszczyk, curtis.windatt.public
Version: 3.4   
Target Milestone: 3.4 M7   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Fix for race condition
none
mylyn/context/zip none

Description Ian Bull CLA 2008-04-22 18:29:00 EDT
Build >= I20080422

1. Checkout something like EMF
2. Launch a runtime workbench
3. Checkout something like EMF examples
4. Notice how we can work with these now (WoHo!)
5. Preferences -> target Platforms -> set the target platform to something else
6. In your list of plug-ins it removes your workspace plug-ins

Now we want to get these back
1. Preferences -> target platform -> set the target platform back
2. Add your src workspace to the list of plugins.

It doesn't seem to let me compile my runtime-workbench plug-ins against my source workspace.  The first time I followed these steps I got this stack trace:

java.lang.NullPointerException
at org.eclipse.pde.internal.core.JavadocLocationManager.processPlugins(JavadocLocationManager.java:127)
at org.eclipse.pde.internal.core.JavadocLocationManager.processExtension(JavadocLocationManager.java:115)
at org.eclipse.pde.internal.core.JavadocLocationManager.initialize(JavadocLocationManager.java:79)
at org.eclipse.pde.internal.core.JavadocLocationManager.getEntry(JavadocLocationManager.java:50)
at org.eclipse.pde.internal.core.JavadocLocationManager.getJavadocLocation(JavadocLocationManager.java:46)
at org.eclipse.pde.internal.core.PDEClasspathContainer.getClasspathAttributes(PDEClasspathContainer.java:123)
at org.eclipse.pde.internal.core.PDEClasspathContainer.addExternalPlugin(PDEClasspathContainer.java:69)
at org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer.addPlugin(RequiredPluginsClasspathContainer.java:255)
at org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer.addDependency(RequiredPluginsClasspathContainer.java:229)
at org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer.addDependency(RequiredPluginsClasspathContainer.java:213)
at org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer.computePluginEntries(RequiredPluginsClasspathContainer.java:129)
at org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer.getClasspathEntries(RequiredPluginsClasspathContainer.java:88)
at org.eclipse.jdt.internal.core.ClasspathEntry.validateClasspathEntry(ClasspathEntry.java:1567)
at org.eclipse.jdt.internal.core.ClasspathValidation.validate(ClasspathValidation.java:69)
at org.eclipse.jdt.internal.core.ChangeClasspathOperation.classpathChanged(ChangeClasspathOperation.java:51)
at org.eclipse.jdt.internal.core.SetContainerOperation.executeOperation(SetContainerOperation.java:112)
at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:709)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:774)
at org.eclipse.jdt.core.JavaCore.setClasspathContainer(JavaCore.java:4702)
at org.eclipse.pde.internal.core.PluginModelManager.updateAffectedEntries(PluginModelManager.java:239)
at org.eclipse.pde.internal.core.PluginModelManager.modelsChanged(PluginModelManager.java:164)
at org.eclipse.pde.internal.core.PluginModelManager.resetState(PluginModelManager.java:853)
at org.eclipse.pde.internal.core.TargetPlatformResetJob.run(TargetPlatformResetJob.java:38)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Comment 1 Curtis Windatt CLA 2008-04-23 12:58:34 EDT
I can get the NPE by adding breakpoints so that there is a target platform reset job still running when a new reset is started.  In your case the classpath computer must have been doing work when you reset.

If we synchronize the call to reset, we avoid the NPE, but we will lock the main thread until the previous reset job (or whatever caused a javadoc lookup) completes.

Note, the manager gets two separate calls to reset, one from the preference page when we hit ok (main thread) and one from the reset job (worker thread).
Comment 2 Curtis Windatt CLA 2008-04-23 13:00:05 EDT
Ian, to get your weaved plugins back (the ones from your host workspace), try turning on the check box for "Build target platform based on the target's installed plugins" and then hit the reset button.
Comment 3 Ian Bull CLA 2008-04-23 13:14:07 EDT
(In reply to comment #2)
> Ian, to get your weaved plugins back (the ones from your host workspace), try
> turning on the check box for "Build target platform based on the target's
> installed plugins" and then hit the reset button.
> 

Cool, that works.

Also, after restarting my run-time workbench, I was able to add my src workspace without getting the NPE.  I guess it was just a bad timing issue that ended up putting me in a bad state.

Good catch Curtis.
Comment 4 Curtis Windatt CLA 2008-04-25 11:17:22 EDT
Created attachment 97623 [details]
Fix for race condition

While it should be decently difficult to reproduce the NPE under normal circumstance, it is not hard to fix.  This patch fixes the race condition by making the reset method synchronized.  To avoid locking the UI while waiting for a lock, the javadoc location reset call made when pressing ok on the preference page is called from a system job.
Comment 5 Curtis Windatt CLA 2008-04-25 11:18:40 EDT
Chris, I don't know if this is something we want to fit in for 3.4, it's a small change, but it isn't likely to be encountered by many users either.
Comment 6 Chris Aniszczyk CLA 2008-04-25 19:26:00 EDT
nice catch.

I have hit this before.
Comment 7 Chris Aniszczyk CLA 2008-04-25 19:26:06 EDT
Created attachment 97703 [details]
mylyn/context/zip
Comment 8 Chris Aniszczyk CLA 2008-04-25 19:27:01 EDT
> 20080425

done. Thanks!
Comment 9 Chris Aniszczyk CLA 2008-04-25 19:35:35 EDT
*** Bug 223141 has been marked as a duplicate of this bug. ***