Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlgoubet2019-09-19 07:32:41 -0400
committerlgoubet2019-09-19 07:34:59 -0400
commit1e8e5f26ded939c2434cb68d641092d270682c01 (patch)
tree2ab0d2dff8c5fd086222282ddbf8bb3ae56b4640
parenteebd410a09df9461857f27a090e5f0b77a823d4e (diff)
downloadorg.eclipse.emf.compare-1e8e5f26ded939c2434cb68d641092d270682c01.tar.gz
org.eclipse.emf.compare-1e8e5f26ded939c2434cb68d641092d270682c01.tar.xz
org.eclipse.emf.compare-1e8e5f26ded939c2434cb68d641092d270682c01.zip
Potential race condition when loading EPackages for comparison
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java
index 0ccd43a5c..1d5c103bc 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java
@@ -272,6 +272,10 @@ public class SynchronizedResourceSet extends ResourceSetImpl implements Disposab
}
final URI normalized = getURIConverter().normalize(uri);
Resource demanded = uriCache.get(normalized);
+ if (namespaceURIs.contains(uri) && demanded != null) {
+ ensurePackageLoaded(demanded);
+ }
+
if (demanded == null) {
final EPackage ePackage = getPackageRegistry().getEPackage(uri.toString());
if (ePackage != null) {
@@ -328,6 +332,23 @@ public class SynchronizedResourceSet extends ResourceSetImpl implements Disposab
}
/**
+ * {@link #loadPackage(URI, URI)} will push the packages' resource in {@link #uriCache cache} before the
+ * package is actually loaded in order to avoid multi-threading issues. However, multi-threading can also
+ * make it so that another thread asks for a resource in cache and return it before the actual loading
+ * ends. This will lock that latter thread until the package is finished loading.
+ */
+ private void ensurePackageLoaded(Resource packageResource) {
+ if (!packageResource.isLoaded() || ((Resource.Internal)packageResource).isLoading()) {
+ packageLoadingLock.lock();
+ try {
+ ensurePackageLoaded(packageResource);
+ } finally {
+ packageLoadingLock.unlock();
+ }
+ }
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecore.resource.impl.ResourceSetImpl#createResource(org.eclipse.emf.common.util.URI)

Back to the top