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 99083 Details for
Bug 226264
race condition in Workspace.isTreeLocked()/setTreeLocked()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Fix v02
patch.txt (text/plain), 9.89 KB, created by
John Arthorne
on 2008-05-07 10:37:17 EDT
(
hide
)
Description:
Fix v02
Filename:
MIME Type:
Creator:
John Arthorne
Created:
2008-05-07 10:37:17 EDT
Size:
9.89 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.resources >Index: src/org/eclipse/core/internal/resources/Workspace.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java,v >retrieving revision 1.218 >diff -u -r1.218 Workspace.java >--- src/org/eclipse/core/internal/resources/Workspace.java 22 Feb 2008 22:50:16 -0000 1.218 >+++ src/org/eclipse/core/internal/resources/Workspace.java 7 May 2008 14:36:05 -0000 >@@ -1865,6 +1865,7 @@ > } > > public void setTreeLocked(boolean locked) { >+ Assert.isTrue(!locked || treeLocked == null, "The workspace tree is already locked"); //$NON-NLS-1$ > treeLocked = locked ? Thread.currentThread() : null; > } > >Index: src/org/eclipse/core/internal/resources/Resource.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Resource.java,v >retrieving revision 1.160 >diff -u -r1.160 Resource.java >--- src/org/eclipse/core/internal/resources/Resource.java 26 Mar 2008 14:55:50 -0000 1.160 >+++ src/org/eclipse/core/internal/resources/Resource.java 7 May 2008 14:36:05 -0000 >@@ -692,6 +692,7 @@ > if (!exists()) > return; > workspace.beginOperation(true); >+ broadcastPreDeleteEvent(); > final IFileStore originalStore = getStore(); > boolean wasLinked = isLinked(); > message = Messages.resources_deleteProblem; >@@ -1397,6 +1398,7 @@ > // and assert for programming errors. See checkMoveRequirements for more information. > assertMoveRequirements(destination, getType(), updateFlags); > workspace.beginOperation(true); >+ broadcastPreMoveEvent(destResource, updateFlags); > IFileStore originalStore = getStore(); > message = Messages.resources_moveProblem; > MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, null); >@@ -1713,7 +1715,6 @@ > tree.standardDeleteFolder((IFolder) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000)); > break; > case IResource.PROJECT : >- workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, this)); > if (!hook.deleteProject(tree, (IProject) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / 2))) > tree.standardDeleteProject((IProject) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000)); > break; >@@ -1725,7 +1726,6 @@ > System.arraycopy(roots, 0, projects, 0, roots.length); > > for (int i = 0; i < projects.length; i++) { >- workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, projects[i])); > if (!hook.deleteProject(tree, projects[i], updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / projects.length / 2))) > tree.standardDeleteProject(projects[i], updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / projects.length)); > } >@@ -1741,14 +1741,10 @@ > IMoveDeleteHook hook = workspace.getMoveDeleteHook(); > switch (getType()) { > case IResource.FILE : >- if (isLinked()) >- workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags)); > if (!hook.moveFile(tree, (IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2))) > tree.standardMoveFile((IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork)); > break; > case IResource.FOLDER : >- if (isLinked()) >- workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags)); > if (!hook.moveFolder(tree, (IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2))) > tree.standardMoveFolder((IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork)); > break; >@@ -1757,8 +1753,6 @@ > // if there is no change in name, there is nothing to do so return. > if (getName().equals(destination.getName())) > return false; >- //we are deleting the source project so notify. >- workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_MOVE, this, destination, updateFlags)); > IProjectDescription description = project.getDescription(); > description.setName(destination.getName()); > if (!hook.moveProject(tree, project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2))) >@@ -1770,4 +1764,37 @@ > } > return true; > } >+ >+ private void broadcastPreDeleteEvent() throws CoreException { >+ switch (getType()) { >+ case IResource.PROJECT : >+ workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, this)); >+ break; >+ case IResource.ROOT : >+ // when the root is deleted, all its children including hidden projects >+ // have to be deleted >+ IResource[] roots = ((Container) this).getChildren(IContainer.INCLUDE_HIDDEN); >+ for (int i = 0; i < roots.length; i++) >+ workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, roots[i])); >+ } >+ } >+ >+ private void broadcastPreMoveEvent(final IResource destination, int updateFlags) throws CoreException { >+ switch (getType()) { >+ case IResource.FILE : >+ if (isLinked()) >+ workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags)); >+ break; >+ case IResource.FOLDER : >+ if (isLinked()) >+ workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags)); >+ break; >+ case IResource.PROJECT : >+ if (!getName().equals(destination.getName())) { >+ // if there is a change in name, we are deleting the source project so notify. >+ workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_MOVE, this, destination, updateFlags)); >+ } >+ break; >+ } >+ } > } >#P org.eclipse.core.tests.resources >Index: src/org/eclipse/core/tests/resources/regression/AllTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/AllTests.java,v >retrieving revision 1.35 >diff -u -r1.35 AllTests.java >--- src/org/eclipse/core/tests/resources/regression/AllTests.java 10 May 2007 13:52:09 -0000 1.35 >+++ src/org/eclipse/core/tests/resources/regression/AllTests.java 7 May 2008 14:36:07 -0000 >@@ -50,6 +50,7 @@ > suite.addTest(Bug_147232.suite()); > suite.addTest(Bug_160251.suite()); > suite.addTest(Bug_165892.suite()); >+ suite.addTest(Bug_226264.suite()); > suite.addTest(IFileTest.suite()); > suite.addTest(IFolderTest.suite()); > suite.addTest(IProjectTest.suite()); >Index: src/org/eclipse/core/tests/resources/regression/Bug_226264.java >=================================================================== >RCS file: src/org/eclipse/core/tests/resources/regression/Bug_226264.java >diff -N src/org/eclipse/core/tests/resources/regression/Bug_226264.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/tests/resources/regression/Bug_226264.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+/******************************************************************************* >+ * Copyright (c) 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.core.tests.resources.regression; >+ >+import junit.framework.Test; >+import junit.framework.TestSuite; >+import org.eclipse.core.resources.*; >+import org.eclipse.core.runtime.*; >+import org.eclipse.core.tests.resources.ResourceTest; >+ >+public class Bug_226264 extends ResourceTest { >+ /** >+ * Constructor for Bug_226264. >+ */ >+ public Bug_226264() { >+ super(); >+ } >+ >+ /** >+ * Constructor for Bug_226264. >+ * @param name >+ */ >+ public Bug_226264(String name) { >+ super(name); >+ } >+ >+ public static Test suite() { >+ return new TestSuite(Bug_226264.class); >+ } >+ >+ public void testBug() throws CoreException { >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ final IProject project1 = workspace.getRoot().getProject("Project1"); >+ project1.create(null); >+ project1.open(null); >+ >+ final IProject project2 = workspace.getRoot().getProject("Project2"); >+ project2.create(null); >+ project2.open(null); >+ >+ final WorkspaceJob job = new WorkspaceJob("job") { >+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { >+ project2.delete(true, null); >+ return Status.OK_STATUS; >+ } >+ }; >+ >+ // the listener will schedule another project delete >+ workspace.addResourceChangeListener(new IResourceChangeListener() { >+ public void resourceChanged(IResourceChangeEvent event) { >+ if (event.getResource() == project1) { >+ // because notification is run in a protected block, >+ // this job will start after the notification >+ job.schedule(); >+ //give the job a chance to start before continuing >+ try { >+ Thread.sleep(2000); >+ } catch (InterruptedException e) { >+ //ignore >+ } >+ } >+ } >+ }, IResourceChangeEvent.PRE_DELETE); >+ >+ // delete project >+ project1.delete(true, null); >+ >+ try { >+ job.join(); >+ } catch (InterruptedException e) { >+ fail("1.0", e); >+ } >+ >+ assertTrue("2.0: " + job.getResult().toString(), job.getResult().isOK()); >+ >+ assertDoesNotExistInWorkspace("3.0", project1); >+ assertDoesNotExistInWorkspace("4.0", project2); >+ } >+}
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
Actions:
View
|
Diff
Attachments on
bug 226264
:
95700
|
95701
|
96625
|
96626
|
98850
| 99083