diff options
Diffstat (limited to 'org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java')
-rw-r--r-- | org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java index d6156980e..928b6d1c2 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -122,7 +122,7 @@ public class ExternalFoldersManager { } while (result.exists()); if (scheduleForCreation) { if (this.pendingFolders == null) - this.pendingFolders = new HashSet(); + this.pendingFolders = Collections.synchronizedSet(new HashSet()); this.pendingFolders.add(externalFolderPath); } knownFolders.put(externalFolderPath, result); @@ -166,16 +166,22 @@ public class ExternalFoldersManager { catch(CoreException e) { throw new JavaModelException(e); } - Iterator iterator = this.pendingFolders.iterator(); - while (iterator.hasNext()) { - Object folderPath = iterator.next(); + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=368152 + // To avoid race condition (from addFolder and removeFolder, load the map elements into an array and clear the map immediately. + // The createLinkFolder being in the synchronized block can cause a deadlock and hence keep it out of the synchronized block. + Object[] arrayOfFolders = null; + synchronized (this.pendingFolders) { + arrayOfFolders = this.pendingFolders.toArray(); + this.pendingFolders.clear(); + } + + for (int i=0; i < arrayOfFolders.length; i++) { try { - createLinkFolder((IPath) folderPath, false, externalFoldersProject, monitor); + createLinkFolder((IPath) arrayOfFolders[i], false, externalFoldersProject, monitor); } catch (CoreException e) { - Util.log(e, "Error while creating a link for external folder :" + folderPath); //$NON-NLS-1$ + Util.log(e, "Error while creating a link for external folder :" + arrayOfFolders[i]); //$NON-NLS-1$ } } - this.pendingFolders.clear(); } public void cleanUp(IProgressMonitor monitor) throws CoreException { |