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

Bug 182665

Summary: [WorkingSets] The working set were not restored at the eclipse launching.
Product: [Eclipse Project] Platform Reporter: Hiroyuki Inaba <hiroyuki.inaba>
Component: UIAssignee: Hitesh <hsoliwal>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: emoffatt, hinaba, masashi.sato
Version: 3.3   
Target Milestone: 3.6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
a sample patch for Eclipse 3.4 none

Description Hiroyuki Inaba CLA 2007-04-16 21:43:44 EDT
Build ID: I20070323-1616

The problem occurred on the following conditions.
- Many projects exists in the workspace.
  About 700: That are Eclipse Project SDK projects, 
             WTP projects, EMF projects and etc.
- 25 or more working sets exists in the workspace.

More information:
NPE occurred at the eclipse launching.

!SESSION 2007-04-17 10:22:29.812 -----------------------------------------------
eclipse.buildId=I20070323-1616
java.version=1.6.0_02-ea
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en
Framework arguments:  -startup c:\eclipse33x.org\eclipse\plugins\org.eclipse.equinox.launcher_1.0.0.v20070319.jar
Command-line arguments:  -os win32 -ws win32 -arch x86 -startup c:\eclipse33x.org\eclipse\plugins\org.eclipse.equinox.launcher_1.0.0.v20070319.jar -clean -debug -data C:\eclipse33x.org\workspace

!ENTRY org.eclipse.jdt.ui 4 2 2007-04-17 10:22:41.484
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ui".
!STACK 0
java.lang.NullPointerException
	at org.eclipse.ui.XMLMemento.getChildren(XMLMemento.java:235)
	at org.eclipse.ui.internal.WorkingSet.restoreWorkingSet(WorkingSet.java:144)
	at org.eclipse.ui.internal.AbstractWorkingSet.getElementsArray(AbstractWorkingSet.java:151)
	at org.eclipse.ui.internal.AbstractWorkingSet.getElements(AbstractWorkingSet.java:139)
	at org.eclipse.jdt.internal.ui.workingsets.WorkingSetModel$ElementMapper.put(WorkingSetModel.java:157)
	at org.eclipse.jdt.internal.ui.workingsets.WorkingSetModel$ElementMapper.rebuild(WorkingSetModel.java:95)
	at org.eclipse.jdt.internal.ui.workingsets.WorkingSetModel.<init>(WorkingSetModel.java:247)
	at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart$10.run(PackageExplorerPart.java:1539)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart.createWorkingSetModel(PackageExplorerPart.java:1537)
	at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart.init(PackageExplorerPart.java:473)
	at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:336)
	at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:219)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:592)
	at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:299)
	at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:531)
	at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:179)
	at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:268)
	at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
	at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:394)
	at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1208)
	at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:639)
	at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:551)
	at org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:563)
	at org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:259)
	at org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:884)
	at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPage.java:2467)
	at org.eclipse.ui.internal.WorkbenchWindow$23.run(WorkbenchWindow.java:2790)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(WorkbenchWindow.java:2771)
	at org.eclipse.ui.internal.WorkbenchWindow$17.runWithException(WorkbenchWindow.java:2116)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3650)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3287)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2260)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2176)
	at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:463)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:458)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:101)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:146)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:356)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:171)
	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:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:476)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:416)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1141)
Comment 1 Hiroyuki Inaba CLA 2007-04-16 22:01:19 EDT
The problem originates in the XML parser (xerces base) included in Sun JDK. 
The problem occurs in Sun JDK 1.5+Eclipse 3.2.1. 

org.eclipse.ui.XMLMemento is called from two threads. 
But, XML DOM(org.w3c.dom.Element) is the thread un-safe. 
Processing where NPE was occurred should change the thread safely 
by using the Java synchronized statement. 

    /* (non-Javadoc)
     * Method declared in IMemento.
     */
    public IMemento getChild(String type) {

==>    	synchronized (element) {

        // Get the nodes.
        NodeList nodes = element.getChildNodes();
        int size = nodes.getLength();
        if (size == 0) {
		return null;
	}

        // Find the first node which is a child of this node.
        for (int nX = 0; nX < size; nX++) {
            Node node = nodes.item(nX);
            if (node instanceof Element) {
                Element element = (Element) node;
                if (element.getNodeName().equals(type)) {
			return new XMLMemento(factory, element);
		}
            }
        }

        // A child was not found.
        return null;

==>    	}
    }

It is thought that other methods of XMLMemoto also use
the Java synchronized sentence, and it is necessary to
change the thread safely.
 
Comment 2 Masashi Sato CLA 2008-09-03 01:10:51 EDT
Created attachment 111549 [details]
a sample patch for Eclipse 3.4
Comment 3 Kim Horne CLA 2008-09-03 08:42:51 EDT
(In reply to comment #1)
> The problem originates in the XML parser (xerces base) included in Sun JDK. 
> The problem occurs in Sun JDK 1.5+Eclipse 3.2.1. 
> 
> org.eclipse.ui.XMLMemento is called from two threads. 
> But, XML DOM(org.w3c.dom.Element) is the thread un-safe. 
> Processing where NPE was occurred should change the thread safely 
> by using the Java synchronized statement. 
> 

What other threads were tryign to read from this?  This may be a case where we fix the caller rather than the memento itself...
Comment 4 Kim Horne CLA 2008-09-03 08:43:47 EDT
Adding Eric as this may be a [Model] issue.
Comment 5 Masashi Sato CLA 2009-03-06 04:06:43 EST
At least, there is a problem in the following codes if Xerces is not a thread safe. 

----------------------------
org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
restoreState(IMemento, IPerspectiveDescriptor)
  :
final IMemento fastViewMem = memento
		.getChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
if (fastViewMem != null) {
	if (fastViewBar != null) {
		StartupThreading.runWithoutExceptions(new StartupRunnable() {

			public void runWithException() {
*				fastViewBar.restoreState(fastViewMem);
			}});
		
	}
}
----------------------------

Because the line of the sign "*" is executed by another thread, the access to same Document will be done from different threads. 



Comment 6 Eric Moffatt CLA 2009-04-27 09:50:32 EDT
Is this still an issue? We haven't seen any duplicates so it's not a commonly encountered scenario...
Comment 7 Masashi Sato CLA 2009-04-27 20:27:41 EDT
I think that it is clear that there is a problem from the source which I mentioned though it is rare that the problem actually occurs. 

> What other threads were tryign to read from this?  This may be a case where we
> fix the caller rather than the memento itself...

Please investigate the thread I mentioned.
Comment 8 Eric Moffatt CLA 2009-04-29 09:05:17 EDT
Hitesh, we have to either act on this or change the target milestone...
Comment 9 Hitesh CLA 2009-04-29 09:13:54 EDT
I think we are better off changing the target milestone. I haven't come across a single occurrence of this problem.I'll take a look at this anyways.
Comment 10 Eric Moffatt CLA 2009-04-29 10:03:42 EDT
I agree...
Comment 11 Hitesh CLA 2009-07-14 09:48:30 EDT

*** This bug has been marked as a duplicate of bug 170205 ***