From 40498ab7e6f21bdfae1996731edb05aedcd0a9e6 Mon Sep 17 00:00:00 2001 From: Eike Stepper Date: Sun, 5 Apr 2020 04:26:22 +0200 Subject: [561779] IllegalStateException: Package 'xyz' contains unresolved proxy https://bugs.eclipse.org/bugs/show_bug.cgi?id=561779 --- .../eclipse/emf/cdo/common/model/CDOModelUtil.java | 64 ++++++++++++---------- .../emf/cdo/internal/server/Repository.java | 7 ++- .../eclipse/emf/cdo/tests/DynamicPackageTest.java | 25 +++------ 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java index 583ba1e872..d075cb76a2 100644 --- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java +++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java @@ -647,72 +647,76 @@ public final class CDOModelUtil implements CDOModelConstants TreeIterator it = ePackage.eAllContents(); while (it.hasNext()) { - EObject e = it.next(); + EObject packageElement = it.next(); - if (e instanceof EAnnotation) + if (packageElement instanceof EAnnotation) { - // we don't need to validate the structure of annotations. The applications that - // define annotations will have to take what they can get + // We don't need to validate the structure of annotations. + // The applications that define annotations will have to take what they can get. it.prune(); } else { - for (EObject r : e.eCrossReferences()) + for (EObject referencedElement : packageElement.eCrossReferences()) { - EObject refTarget = null; + EObject referenceTarget = null; - if (r.eIsProxy()) + if (referencedElement.eIsProxy()) { - String msg = "Package '%s' contains unresolved proxy '%s'"; - msg = String.format(msg, ePackage.getNsURI(), ((InternalEObject)r).eProxyURI()); - throw new IllegalStateException(msg); + referencedElement = EcoreUtil.resolve(referencedElement, (ResourceSet)null); + if (referencedElement.eIsProxy()) + { + String msg = "Package '%s' contains unresolved proxy '%s'"; + msg = String.format(msg, ePackage.getNsURI(), ((InternalEObject)referencedElement).eProxyURI()); + throw new IllegalStateException(msg); + } } - if (r.eResource() != null && r.eResource() != e.eResource()) + if (referencedElement.eResource() != null && referencedElement.eResource() != packageElement.eResource()) { - // It's a ref into another resource - EPackage pkg = null; - if (r instanceof EClassifier) + // It's a reference into another resource. + EPackage referencedPackage = null; + if (referencedElement instanceof EClassifier) { - refTarget = r; - pkg = ((EClassifier)r).getEPackage(); + referenceTarget = referencedElement; + referencedPackage = ((EClassifier)referencedElement).getEPackage(); } - else if (r instanceof EStructuralFeature) + else if (referencedElement instanceof EStructuralFeature) { - refTarget = r; - EStructuralFeature feature = (EStructuralFeature)r; + referenceTarget = referencedElement; + EStructuralFeature feature = (EStructuralFeature)referencedElement; EClass ownerClass = (EClass)feature.eContainer(); - pkg = ownerClass.getEPackage(); + referencedPackage = ownerClass.getEPackage(); } - else if (r instanceof EGenericType) + else if (referencedElement instanceof EGenericType) { - EGenericType genType = (EGenericType)r; + EGenericType genType = (EGenericType)referencedElement; EClassifier c = genType.getEClassifier(); if (c != null) { - refTarget = c; - pkg = c.getEPackage(); + referenceTarget = c; + referencedPackage = c.getEPackage(); } } - if (pkg == null) + if (referencedPackage == null) { continue; } - while (pkg.getESuperPackage() != null) + while (referencedPackage.getESuperPackage() != null) { - pkg = pkg.getESuperPackage(); + referencedPackage = referencedPackage.getESuperPackage(); } - String resourceURI = refTarget.eResource().getURI().toString(); - if (!resourceURI.toString().equals(pkg.getNsURI())) + String resourceURI = referenceTarget.eResource().getURI().toString(); + if (!resourceURI.toString().equals(referencedPackage.getNsURI())) { String msg = "URI of the resource (%s) does not match the nsURI (%s) of the top-level package;\n" + "this can be fixed by calling Resource.setURI(URI) after loading the packages,\n" + "or by configuring a URI mapping from nsURI's to location URI's before loading the packages,\n" + "and then loading them with their nsURI's"; - msg = String.format(msg, resourceURI, pkg.getNsURI()); + msg = String.format(msg, resourceURI, referencedPackage.getNsURI()); throw new IllegalStateException(msg); } } diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java index e18ef1a235..d37097abeb 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java @@ -2442,9 +2442,12 @@ public class Repository extends Container implements InternalRepository, for (InternalCDOPackageUnit packageUnit : packageUnits) { packageRegistry.putPackageUnit(packageUnit); + } - // Bug 521029: Initialize EPackages early from the main thread to avoid multi-threading issues. - // This could be made optional at some point. + // Bug 521029: Initialize EPackages early from the main thread to avoid multi-threading issues. + // This could be made optional at some point. + for (InternalCDOPackageUnit packageUnit : packageUnits) + { for (InternalCDOPackageInfo packageInfo : packageUnit.getPackageInfos()) { packageInfo.getEPackage(true); // Trigger initialization. diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DynamicPackageTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DynamicPackageTest.java index 6cc8eb6e17..1bc30ae094 100644 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DynamicPackageTest.java +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DynamicPackageTest.java @@ -31,18 +31,15 @@ import org.eclipse.emf.ecore.impl.DynamicEObjectImpl; */ public class DynamicPackageTest extends AbstractCDOTest { - protected static EClass mapContainerEClass; - public void testDynamicMaps() throws Exception { - CDOSession session = openSession(); - CDOTransaction transaction = session.openTransaction(); EPackage dynamicMapEPackge = createPackage(); EFactory dynamicMapEFactoryInstance = dynamicMapEPackge.getEFactoryInstance(); - - CDOResource resource = transaction.createResource(getResourcePath("/test1")); EObject mapContainer = dynamicMapEFactoryInstance.create((EClass)dynamicMapEPackge.getEClassifier("MapContainer")); + CDOSession session = openSession(); + CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.createResource(getResourcePath("/test1")); resource.getContents().add(mapContainer); transaction.commit(); @@ -56,23 +53,19 @@ public class DynamicPackageTest extends AbstractCDOTest } } - public EPackage createPackage() + private EPackage createPackage() { - EcoreFactory theCoreFactory = EcoreFactory.eINSTANCE; - EcorePackage theCorePackage = EcorePackage.eINSTANCE; + EStructuralFeature name = EcoreFactory.eINSTANCE.createEAttribute(); + name.setName("name"); + name.setEType(EcorePackage.eINSTANCE.getEString()); - mapContainerEClass = theCoreFactory.createEClass(); + EClass mapContainerEClass = EcoreFactory.eINSTANCE.createEClass(); mapContainerEClass.setName("MapContainer"); + mapContainerEClass.getEStructuralFeatures().add(name); EPackage dynamicMapEPackage = createUniquePackage(); dynamicMapEPackage.getEClassifiers().add(mapContainerEClass); - EStructuralFeature name = theCoreFactory.createEAttribute(); - name.setName("name"); - name.setEType(theCorePackage.getEString()); - - mapContainerEClass.getEStructuralFeatures().add(name); - if (!isConfig(LEGACY)) { CDOUtil.prepareDynamicEPackage(dynamicMapEPackage); -- cgit v1.2.3