Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 368152 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java (-19 / +3 lines)
Lines 101-107 Link Here
101
import java.util.HashMap;
101
import java.util.HashMap;
102
import java.util.HashSet;
102
import java.util.HashSet;
103
import java.util.Hashtable;
103
import java.util.Hashtable;
104
import java.util.Iterator;
105
import java.util.Map;
104
import java.util.Map;
106
105
107
import org.eclipse.core.runtime.CoreException;
106
import org.eclipse.core.runtime.CoreException;
Lines 117-123 Link Here
117
import org.eclipse.core.runtime.QualifiedName;
116
import org.eclipse.core.runtime.QualifiedName;
118
import org.eclipse.core.runtime.SubProgressMonitor;
117
import org.eclipse.core.runtime.SubProgressMonitor;
119
import org.eclipse.core.runtime.jobs.ISchedulingRule;
118
import org.eclipse.core.runtime.jobs.ISchedulingRule;
120
import org.eclipse.core.runtime.jobs.Job;
121
119
122
import org.eclipse.core.resources.IContainer;
120
import org.eclipse.core.resources.IContainer;
123
import org.eclipse.core.resources.IFile;
121
import org.eclipse.core.resources.IFile;
Lines 3890-3896 Link Here
3890
				monitor.subTask(Messages.javamodel_resetting_source_attachment_properties);
3888
				monitor.subTask(Messages.javamodel_resetting_source_attachment_properties);
3891
			final IJavaProject[] projects = manager.getJavaModel().getJavaProjects();
3889
			final IJavaProject[] projects = manager.getJavaModel().getJavaProjects();
3892
			HashSet visitedPaths = new HashSet();
3890
			HashSet visitedPaths = new HashSet();
3893
			HashSet externalPaths = new HashSet();
3894
			ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
3891
			ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
3895
			for (int i = 0, length = projects.length; i < length; i++) {
3892
			for (int i = 0, length = projects.length; i < length; i++) {
3896
				JavaProject javaProject = (JavaProject) projects[i];
3893
				JavaProject javaProject = (JavaProject) projects[i];
Lines 3914-3945 Link Here
3914
						if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
3911
						if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
3915
							IPath entryPath = entry.getPath();
3912
							IPath entryPath = entry.getPath();
3916
							if (ExternalFoldersManager.isExternalFolderPath(entryPath) && externalFoldersManager.getFolder(entryPath) == null) {
3913
							if (ExternalFoldersManager.isExternalFolderPath(entryPath) && externalFoldersManager.getFolder(entryPath) == null) {
3917
								externalPaths.add(entryPath);
3914
								externalFoldersManager.addFolder(entryPath, true);
3918
							}
3915
							}
3919
						}
3916
						}
3920
					}
3917
					}
3921
				}
3918
				}
3922
			}
3919
			}
3923
			
3924
			ISchedulingRule rule = null;
3925
			try {
3920
			try {
3926
				// Use a schedule rule to avoid a race condition (https://bugs.eclipse.org/bugs/show_bug.cgi?id=369251)
3927
				rule = ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(externalFoldersManager.getExternalFoldersProject());
3928
				Job.getJobManager().beginRule(rule, monitor);
3929
				
3930
				Iterator externalPathIter = externalPaths.iterator();
3931
				while (externalPathIter.hasNext()) {
3932
					externalFoldersManager.addFolder((IPath) externalPathIter.next(), true);
3933
				}
3934
				externalFoldersManager.createPendingFolders(monitor);
3921
				externalFoldersManager.createPendingFolders(monitor);
3935
				
3922
			}
3936
			} catch (JavaModelException jme) {
3923
			catch(JavaModelException jme) {
3937
				// Creation of external folder project failed. Log it and continue;
3924
				// Creation of external folder project failed. Log it and continue;
3938
				Util.log(jme, "Error while processing external folders"); //$NON-NLS-1$
3925
				Util.log(jme, "Error while processing external folders"); //$NON-NLS-1$
3939
			} finally {
3940
				Job.getJobManager().endRule(rule);
3941
			}
3926
			}
3942
			
3943
			// initialize delta state
3927
			// initialize delta state
3944
			if (monitor != null)
3928
			if (monitor != null)
3945
				monitor.subTask(Messages.javamodel_initializing_delta_state);
3929
				monitor.subTask(Messages.javamodel_initializing_delta_state);
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java (-7 / +13 lines)
Lines 122-128 Link Here
122
		} while (result.exists());
122
		} while (result.exists());
123
		if (scheduleForCreation) {
123
		if (scheduleForCreation) {
124
			if (this.pendingFolders == null)
124
			if (this.pendingFolders == null)
125
				this.pendingFolders = new HashSet();
125
				this.pendingFolders = Collections.synchronizedSet(new HashSet());
126
			this.pendingFolders.add(externalFolderPath);
126
			this.pendingFolders.add(externalFolderPath);
127
		}
127
		}
128
		knownFolders.put(externalFolderPath, result);
128
		knownFolders.put(externalFolderPath, result);
Lines 166-181 Link Here
166
		catch(CoreException e) {
166
		catch(CoreException e) {
167
			throw new JavaModelException(e);
167
			throw new JavaModelException(e);
168
		}
168
		}
169
		Iterator iterator = this.pendingFolders.iterator();
169
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=368152
170
		while (iterator.hasNext()) {
170
		// To avoid race condition (from addFolder and removeFolder, load the map elements into an array and clear the map immediately.
171
			Object folderPath = iterator.next();
171
		// The createLinkFolder being in the synchronized block can cause a deadlock and hence keep it out of the synchronized block. 
172
		Object[] arrayOfFolders = null;
173
		synchronized (this.pendingFolders) {
174
			arrayOfFolders = this.pendingFolders.toArray();
175
			this.pendingFolders.clear();
176
		}
177
178
		for (int i=0; i < arrayOfFolders.length; i++) {
172
			try {
179
			try {
173
				createLinkFolder((IPath) folderPath, false, externalFoldersProject, monitor);
180
				createLinkFolder((IPath) arrayOfFolders[i], false, externalFoldersProject, monitor);
174
			} catch (CoreException e) {
181
			} catch (CoreException e) {
175
				Util.log(e, "Error while creating a link for external folder :" + folderPath); //$NON-NLS-1$
182
				Util.log(e, "Error while creating a link for external folder :" + arrayOfFolders[i]); //$NON-NLS-1$
176
			}
183
			}
177
		}
184
		}
178
		this.pendingFolders.clear();
179
	}
185
	}
180
	
186
	
181
	public void cleanUp(IProgressMonitor monitor) throws CoreException {
187
	public void cleanUp(IProgressMonitor monitor) throws CoreException {

Return to bug 368152