[181334] Deadlock caused by StructureEdit.getComponentModelRoot()
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleCoreValidator.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleCoreValidator.java
index 8c4c23c..7a212d0 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleCoreValidator.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleCoreValidator.java
@@ -15,14 +15,12 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
-import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.wst.common.componentcore.ModuleCoreNature;
import org.eclipse.wst.common.componentcore.internal.impl.WTPModulesResource;
import org.eclipse.wst.common.internal.emf.resource.TranslatorResource;
-import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
import org.eclipse.wst.common.project.facet.core.internal.FacetedProjectNature;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.core.ValidationException;
@@ -41,24 +39,23 @@
}
public Resource getPrimaryResource(IProject project) {
- // Overriden to handle loading the .component resource in new and old forms
- // First will try to load from .settings/org.eclipse.wst.common.component
- // Second will try to load from the old location(s) .settings/.component or .component
-
- URI uri = URI.createURI(StructureEdit.MODULE_META_FILE_NAME);
- WTPModulesResource res = (WTPModulesResource)WorkbenchResourceHelper.getOrCreateResource(uri, getResourceSet(project));
- if (res == null || !res.isLoaded()) {
- uri = URI.createURI(".settings/.component");
- res = (WTPModulesResource)WorkbenchResourceHelper.getOrCreateResource(uri, getResourceSet(project));
- if (res == null || !res.isLoaded()) {
- uri = URI.createURI(".wtpmodules");
- res = (WTPModulesResource)WorkbenchResourceHelper.getOrCreateResource(uri, getResourceSet(project));
- if (res == null || !res.isLoaded()) {
- res = null;
+ // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=181334; Changing this method to call ModuleStructuralModel.getPrimaryResource() method instead.
+ // This does two things:
+ // 1. Reorders the locks to prevent deadlock between locking the resource (Bugzilla 181334),
+ // then the edit model and
+ // 2. Reuses code. (The code between this method and MSM.getPrimaryResource() is identical.
+ StructureEdit structureEdit = StructureEdit.getStructureEditForRead(project);
+ if (structureEdit != null) {
+ ModuleStructuralModel structuralModel = structureEdit.getModuleStructuralModel();
+ if (structuralModel != null) {
+ // acquiring the ModuleStructuralModel lock here first because the call to getPrimaryResource()
+ // will cause this lock to be acquired later resulting in a potential deadlock
+ synchronized (structuralModel) {
+ return structuralModel.getPrimaryResource();
}
}
}
- return res;
+ return null;
}
private ResourceSet getResourceSet(IProject proj) {