Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 127694 Details for
Bug 194917
stack overflow error from working set management
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch v1
patch aggregate sets 3.txt (text/plain), 19.52 KB, created by
Oleg Besedin
on 2009-03-05 14:13:10 EST
(
hide
)
Description:
Patch v1
Filename:
MIME Type:
Creator:
Oleg Besedin
Created:
2009-03-05 14:13:10 EST
Size:
19.52 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java,v >retrieving revision 1.114 >diff -u -r1.114 WorkbenchMessages.java >--- Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java 3 Mar 2009 18:32:24 -0000 1.114 >+++ Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java 5 Mar 2009 18:56:46 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >+ * Copyright (c) 2005, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -816,6 +816,7 @@ > public static String ProblemRestoringWorkingSetState_message; > > public static String ProblemRestoringWorkingSetState_title; >+ public static String ProblemCyclicDependency; > > public static String WorkingSetEditWizard_title; > public static String WorkingSetNewWizard_title; >Index: Eclipse UI/org/eclipse/ui/internal/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties,v >retrieving revision 1.394 >diff -u -r1.394 messages.properties >--- Eclipse UI/org/eclipse/ui/internal/messages.properties 3 Mar 2009 18:32:24 -0000 1.394 >+++ Eclipse UI/org/eclipse/ui/internal/messages.properties 5 Mar 2009 18:56:46 -0000 >@@ -787,6 +787,7 @@ > ProblemSavingWorkingSetState_title = Saving Problems > ProblemRestoringWorkingSetState_message = Unable to restore working set state. > ProblemRestoringWorkingSetState_title = Restoring Problems >+ProblemCyclicDependency = Removed cyclic dependency in the working set ''{0}''. > > WorkingSetEditWizard_title=Edit Working Set > WorkingSetNewWizard_title=New Working Set >Index: Eclipse UI/org/eclipse/ui/internal/AggregateWorkingSet.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/AggregateWorkingSet.java,v >retrieving revision 1.11 >diff -u -r1.11 AggregateWorkingSet.java >--- Eclipse UI/org/eclipse/ui/internal/AggregateWorkingSet.java 29 Jan 2009 19:10:13 -0000 1.11 >+++ Eclipse UI/org/eclipse/ui/internal/AggregateWorkingSet.java 5 Mar 2009 18:56:46 -0000 >@@ -19,6 +19,7 @@ > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.util.IPropertyChangeListener; > import org.eclipse.jface.util.PropertyChangeEvent; >+import org.eclipse.osgi.util.NLS; > import org.eclipse.ui.IAggregateWorkingSet; > import org.eclipse.ui.IMemento; > import org.eclipse.ui.IWorkingSet; >@@ -35,6 +36,11 @@ > private IWorkingSet[] components; > > /** >+ * Prevents stack overflow on cyclic element inclusions. >+ */ >+ private boolean inElementConstruction = false; >+ >+ /** > * > * @param name > * @param label >@@ -77,17 +83,40 @@ > * @param fireEvent whether a working set change event should be fired > */ > private void constructElements(boolean fireEvent) { >- Set elements = new HashSet(); >- IWorkingSet[] localComponents = getComponentsInternal(); >- for (int i = 0; i < localComponents.length; i++) { >- IWorkingSet workingSet = localComponents[i]; >- elements.addAll(Arrays.asList(workingSet.getElements())); >- } >- internalSetElements((IAdaptable[]) elements >- .toArray(new IAdaptable[elements.size()])); >- if (fireEvent) { >- fireWorkingSetChanged( >- IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE, null); >+ if (inElementConstruction) { >+ String msg = NLS.bind(WorkbenchMessages.ProblemCyclicDependency, getName()); >+ WorkbenchPlugin.log(msg); >+ throw new IllegalStateException(msg); >+ } >+ inElementConstruction = true; >+ try { >+ Set elements = new HashSet(); >+ IWorkingSet[] localComponents = getComponentsInternal(); >+ for (int i = 0; i < localComponents.length; i++) { >+ IWorkingSet workingSet = localComponents[i]; >+ try { >+ IAdaptable[] componentElements = workingSet.getElements(); >+ elements.addAll(Arrays.asList(componentElements)); >+ } catch (IllegalStateException e) { // an invalid component; remove it >+ IWorkingSet[] tmp = new IWorkingSet[components.length - 1]; >+ if (i > 0) >+ System.arraycopy(components, 0, tmp, 0, i); >+ if (components.length - i - 1 > 0) >+ System.arraycopy(components, i + 1, tmp, i, components.length - i - 1); >+ components = tmp; >+ workingSetMemento = null; // toss cached info >+ fireWorkingSetChanged(IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE, null); >+ continue; >+ } >+ } >+ internalSetElements((IAdaptable[]) elements >+ .toArray(new IAdaptable[elements.size()])); >+ if (fireEvent) { >+ fireWorkingSetChanged( >+ IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE, null); >+ } >+ } finally { >+ inElementConstruction = false; > } > } > >@@ -150,7 +179,9 @@ > } > > public void disconnect() { >- getManager().removePropertyChangeListener(this); >+ IWorkingSetManager connectedManager = getManager(); >+ if (connectedManager != null) >+ connectedManager.removePropertyChangeListener(this); > super.disconnect(); > } > >Index: Eclipse UI/org/eclipse/ui/IWorkingSet.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkingSet.java,v >retrieving revision 1.29 >diff -u -r1.29 IWorkingSet.java >--- Eclipse UI/org/eclipse/ui/IWorkingSet.java 22 Jan 2009 11:14:34 -0000 1.29 >+++ Eclipse UI/org/eclipse/ui/IWorkingSet.java 5 Mar 2009 18:56:46 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -26,7 +26,10 @@ > public interface IWorkingSet extends IPersistableElement, IAdaptable { > /** > * Returns the elements that are contained in this working set. >- * >+ * <p> >+ * This method might throw an {@link IllegalStateException} if >+ * the working set is invalid. >+ * </p> > * @return the working set's elements > */ > public IAdaptable[] getElements(); >#P org.eclipse.ui.tests >Index: Eclipse UI Tests/org/eclipse/ui/tests/api/IAggregateWorkingSetTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IAggregateWorkingSetTest.java,v >retrieving revision 1.1 >diff -u -r1.1 IAggregateWorkingSetTest.java >--- Eclipse UI Tests/org/eclipse/ui/tests/api/IAggregateWorkingSetTest.java 23 Jan 2009 18:09:25 -0000 1.1 >+++ Eclipse UI Tests/org/eclipse/ui/tests/api/IAggregateWorkingSetTest.java 5 Mar 2009 18:56:47 -0000 >@@ -1,103 +1,209 @@ >-/******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.ui.tests.api; >- >-import org.eclipse.core.resources.IWorkspace; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.IAdaptable; >-import org.eclipse.ui.IAggregateWorkingSet; >-import org.eclipse.ui.IMemento; >-import org.eclipse.ui.IWorkingSet; >-import org.eclipse.ui.IWorkingSetManager; >-import org.eclipse.ui.XMLMemento; >-import org.eclipse.ui.internal.IWorkbenchConstants; >-import org.eclipse.ui.tests.harness.util.ArrayUtil; >-import org.eclipse.ui.tests.harness.util.UITestCase; >- >-public class IAggregateWorkingSetTest extends UITestCase { >- >- final static String WORKING_SET_NAME = "testws"; >- final static String AGGREGATE_WORKING_SET_NAME_ = "testaggregatews"; >- >- IWorkspace fWorkspace; >- >- IWorkingSet[] components; >- IAggregateWorkingSet fWorkingSet; >- >- public IAggregateWorkingSetTest(String testName) { >- super(testName); >- } >- >- protected void doSetUp() throws Exception { >- super.doSetUp(); >- IWorkingSetManager workingSetManager = fWorkbench >- .getWorkingSetManager(); >- >- fWorkspace = ResourcesPlugin.getWorkspace(); >- components = new IWorkingSet[4]; >- for (int i = 0; i < 4; i++) { >- components[i] = workingSetManager.createWorkingSet(WORKING_SET_NAME >- + i, new IAdaptable[] {}); >- workingSetManager.addWorkingSet(components[i]); >- } >- fWorkingSet = (IAggregateWorkingSet) workingSetManager >- .createAggregateWorkingSet(AGGREGATE_WORKING_SET_NAME_, >- AGGREGATE_WORKING_SET_NAME_, components); >- >- workingSetManager.addWorkingSet(fWorkingSet); >- } >- protected void doTearDown() throws Exception { >- IWorkingSetManager workingSetManager = fWorkbench.getWorkingSetManager(); >- workingSetManager.removeWorkingSet(fWorkingSet); >- for (int i = 0; i < components.length; i++) { >- workingSetManager.removeWorkingSet(components[i]); >- } >- super.doTearDown(); >- } >- >- public void testSaveWSet() throws Throwable { >- //<possible client code> >- IWorkingSetManager workingSetManager = fWorkbench >- .getWorkingSetManager(); >- IWorkingSet set=workingSetManager.getWorkingSet(AGGREGATE_WORKING_SET_NAME_); >- if(set.isAggregateWorkingSet()){ >- IWorkingSet[] sets=((IAggregateWorkingSet)set).getComponents(); >- if(sets.length>=1){ >- sets[0]=null; //client fails to pay enough attention to specs or unknowingly does this >- } >- } >- //</possible client code> >- //error makes it look like it comes from workingsets api, with no clue about the actual culprit >- IMemento memento=XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_WORKING_SET); >- set.saveState(memento); >- } >- public void testGetElemets() throws Throwable { >- //<possible client code> >- IWorkingSetManager workingSetManager = fWorkbench >- .getWorkingSetManager(); >- IWorkingSet set=workingSetManager.getWorkingSet(AGGREGATE_WORKING_SET_NAME_); >- if(set.isAggregateWorkingSet()){ >- IWorkingSet[] sets=((IAggregateWorkingSet)set).getComponents(); >- if(sets.length>1){ >- //code 2 fails to pay enough attention to specs or unknowingly does this >- sets[0]=workingSetManager.createWorkingSet(WORKING_SET_NAME, new IAdaptable[] { fWorkspace.getRoot() }); >- //code 1 part removes a workingset >- workingSetManager.removeWorkingSet(sets[1]); >- } >- } >- //</possible client code> >- >- //unexpected >- assertTrue(ArrayUtil.equals( >- new IAdaptable[] {}, >- fWorkingSet.getElements())); >- } >-} >+/******************************************************************************* >+ * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.tests.api; >+ >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.IAdaptable; >+import org.eclipse.ui.IAggregateWorkingSet; >+import org.eclipse.ui.IMemento; >+import org.eclipse.ui.IWorkingSet; >+import org.eclipse.ui.IWorkingSetManager; >+import org.eclipse.ui.XMLMemento; >+import org.eclipse.ui.internal.IWorkbenchConstants; >+import org.eclipse.ui.tests.harness.util.ArrayUtil; >+import org.eclipse.ui.tests.harness.util.UITestCase; >+ >+public class IAggregateWorkingSetTest extends UITestCase { >+ >+ final static String WORKING_SET_NAME = "testws"; >+ final static String AGGREGATE_WORKING_SET_NAME_ = "testaggregatews"; >+ >+ IWorkspace fWorkspace; >+ >+ IWorkingSet[] components; >+ IAggregateWorkingSet fWorkingSet; >+ >+ public IAggregateWorkingSetTest(String testName) { >+ super(testName); >+ } >+ >+ protected void doSetUp() throws Exception { >+ super.doSetUp(); >+ IWorkingSetManager workingSetManager = fWorkbench >+ .getWorkingSetManager(); >+ >+ fWorkspace = ResourcesPlugin.getWorkspace(); >+ components = new IWorkingSet[4]; >+ for (int i = 0; i < 4; i++) { >+ components[i] = workingSetManager.createWorkingSet(WORKING_SET_NAME >+ + i, new IAdaptable[] {}); >+ workingSetManager.addWorkingSet(components[i]); >+ } >+ fWorkingSet = (IAggregateWorkingSet) workingSetManager >+ .createAggregateWorkingSet(AGGREGATE_WORKING_SET_NAME_, >+ AGGREGATE_WORKING_SET_NAME_, components); >+ >+ workingSetManager.addWorkingSet(fWorkingSet); >+ } >+ protected void doTearDown() throws Exception { >+ IWorkingSetManager workingSetManager = fWorkbench.getWorkingSetManager(); >+ workingSetManager.removeWorkingSet(fWorkingSet); >+ for (int i = 0; i < components.length; i++) { >+ workingSetManager.removeWorkingSet(components[i]); >+ } >+ super.doTearDown(); >+ } >+ >+ public void testSaveWSet() throws Throwable { >+ //<possible client code> >+ IWorkingSetManager workingSetManager = fWorkbench >+ .getWorkingSetManager(); >+ IWorkingSet set=workingSetManager.getWorkingSet(AGGREGATE_WORKING_SET_NAME_); >+ if(set.isAggregateWorkingSet()){ >+ IWorkingSet[] sets=((IAggregateWorkingSet)set).getComponents(); >+ if(sets.length>=1){ >+ sets[0]=null; //client fails to pay enough attention to specs or unknowingly does this >+ } >+ } >+ //</possible client code> >+ //error makes it look like it comes from workingsets api, with no clue about the actual culprit >+ IMemento memento=XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_WORKING_SET); >+ set.saveState(memento); >+ } >+ public void testGetElemets() throws Throwable { >+ //<possible client code> >+ IWorkingSetManager workingSetManager = fWorkbench >+ .getWorkingSetManager(); >+ IWorkingSet set=workingSetManager.getWorkingSet(AGGREGATE_WORKING_SET_NAME_); >+ if(set.isAggregateWorkingSet()){ >+ IWorkingSet[] sets=((IAggregateWorkingSet)set).getComponents(); >+ if(sets.length>1){ >+ //code 2 fails to pay enough attention to specs or unknowingly does this >+ sets[0]=workingSetManager.createWorkingSet(WORKING_SET_NAME, new IAdaptable[] { fWorkspace.getRoot() }); >+ //code 1 part removes a workingset >+ workingSetManager.removeWorkingSet(sets[1]); >+ } >+ } >+ //</possible client code> >+ >+ //unexpected >+ assertTrue(ArrayUtil.equals( >+ new IAdaptable[] {}, >+ fWorkingSet.getElements())); >+ } >+ >+ /** >+ * Core of the problem: while Eclipse is running, name collisions among working sets >+ * don't matter. However, on save and restart names will be used to identify working >+ * sets, which could possibly lead to cycles in aggregate working sets. >+ * >+ * Bottom line: if there are multiple aggregate working sets with the same name, expect >+ * trouble on restart. >+ * >+ * To create a cycle we have to be creative: >+ * - create an aggregate1 with an ID = "testCycle" >+ * - create an aggregate2 with an ID = "testCycle" containing aggregate1 >+ * - save it into IMemento >+ * >+ * Now the IMememnto creates a self reference: >+ * >+ * <workingSet name="testCycle" label="testCycle" aggregate="true"> >+ * <workingSet IMemento.internal.id="testCycle" /> >+ * </workingSet> >+ * >+ * All we have to do to emulate stack overflow is to create a working set based on this IMemento. >+ * >+ * @throws Throwable >+ */ >+ public void testWorkingSetCycle() throws Throwable { >+ IWorkingSetManager manager = fWorkbench.getWorkingSetManager(); >+ >+ // create an IMemento with a cycle in it >+ IAggregateWorkingSet aggregate = (IAggregateWorkingSet) manager >+ .createAggregateWorkingSet("testCycle","testCycle", new IWorkingSet[0]); >+ >+ IAggregateWorkingSet aggregate2 = (IAggregateWorkingSet) manager >+ .createAggregateWorkingSet("testCycle","testCycle", new IWorkingSet[] {aggregate}); >+ >+ IMemento memento=XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_WORKING_SET); >+ aggregate2.saveState(memento); >+ >+ // load the IMemento >+ IAggregateWorkingSet aggregateReloaded = null; >+ try { >+ aggregateReloaded = (IAggregateWorkingSet) manager.createWorkingSet(memento); >+ manager.addWorkingSet(aggregateReloaded); >+ aggregateReloaded.getComponents(); >+ } catch (StackOverflowError e) { >+ e.printStackTrace(); >+ fail("Stack overflow for self-referenced aggregate working set", e); >+ } finally { >+ if (aggregateReloaded != null) >+ manager.removeWorkingSet(aggregateReloaded); >+ } >+ } >+ >+ /** >+ * Tests cleanup of the cycle from an aggregate working set. >+ * @throws Throwable >+ */ >+ public void testCycleCleanup() throws Throwable { >+ IWorkingSetManager manager = fWorkbench.getWorkingSetManager(); >+ >+ // create an IMemento with a cycle in it: { good, good, cycle, good, good } >+ IAggregateWorkingSet aggregateSub0 = (IAggregateWorkingSet) manager >+ .createAggregateWorkingSet("testCycle0","testCycle0", new IWorkingSet[0]); >+ >+ IAggregateWorkingSet aggregateSub1 = (IAggregateWorkingSet) manager >+ .createAggregateWorkingSet("testCycle1","testCycle1", new IWorkingSet[0]); >+ >+ IAggregateWorkingSet aggregateSub2 = (IAggregateWorkingSet) manager >+ .createAggregateWorkingSet("testCycle","testCycle", new IWorkingSet[0]); // cycle >+ >+ IAggregateWorkingSet aggregateSub3 = (IAggregateWorkingSet) manager >+ .createAggregateWorkingSet("testCycle3","testCycle3", new IWorkingSet[0]); >+ >+ IAggregateWorkingSet aggregateSub4 = (IAggregateWorkingSet) manager >+ .createAggregateWorkingSet("testCycle4","testCycle4", new IWorkingSet[0]); >+ >+ >+ IAggregateWorkingSet aggregate = (IAggregateWorkingSet) manager >+ .createAggregateWorkingSet("testCycle","testCycle", new IWorkingSet[] {aggregateSub0, >+ aggregateSub1, aggregateSub2, aggregateSub3, aggregateSub4}); >+ >+ manager.addWorkingSet(aggregateSub0); >+ manager.addWorkingSet(aggregateSub1); >+ manager.addWorkingSet(aggregateSub3); >+ manager.addWorkingSet(aggregateSub4); >+ >+ IMemento memento=XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_WORKING_SET); >+ aggregate.saveState(memento); >+ >+ // load the IMemento >+ IAggregateWorkingSet aggregateReloaded = null; >+ try { >+ aggregateReloaded = (IAggregateWorkingSet) manager.createWorkingSet(memento); >+ manager.addWorkingSet(aggregateReloaded); >+ IWorkingSet[] aggregates = aggregateReloaded.getComponents(); >+ assertNotNull(aggregates); >+ assertEquals(4, aggregates.length); >+ for(int i = 0; i < aggregates.length; i++) >+ assertFalse("testCycle".equals(aggregates[i].getName())); >+ } catch (StackOverflowError e) { >+ e.printStackTrace(); >+ fail("Stack overflow for self-referenced aggregate working set", e); >+ } finally { >+ if (aggregateReloaded != null) >+ manager.removeWorkingSet(aggregateReloaded); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
emoffatt
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 194917
:
100844
|
127554
| 127694 |
127804