javaumlrational-rsa

Exception while opening a UML Model in Rational Software Architect


I'm having a problem with Rational Software Architect 8.0. I'm developing a plugin that provides some extra features to models. I'm trying to write unit tests to make sure that my plugin behaves as expected.

As a part of some of these tests, I need to open a UML model (emx format) and do some operations on it. I use com.ibm.xtools.modeler.ui.UMLModeler.openModelResource(..) for that, but it throws a strange exception. Here is the code snippet:

Element root = null;
try {
    root = UMLModeler.openModelResource(fileName);
} catch (IOException e) {
    System.out.println("Error while opening model " + fileName + ": " + e.getMessage());
}
return root;

And here is the exception being thrown:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
    at org.eclipse.gmf.runtime.emf.core.internal.domain.MSLEditingDomain$MSLResourceSet.addURIHandlers(MSLEditingDomain.java:2282)
    at org.eclipse.gmf.runtime.emf.core.internal.domain.MSLEditingDomain$MSLResourceSet.<init>(MSLEditingDomain.java:2315)
    at org.eclipse.gmf.runtime.emf.core.internal.domain.MSLEditingDomain.<init>(MSLEditingDomain.java:255)
    at org.eclipse.gmf.runtime.emf.core.internal.domain.MSLEditingDomain.<init>(MSLEditingDomain.java:234)
    at org.eclipse.gmf.runtime.emf.core.edit.MEditingDomain.createDefaultEditingDomain(MEditingDomain.java:112)
    at org.eclipse.gmf.runtime.emf.core.edit.MEditingDomain.<clinit>(MEditingDomain.java:70)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    at org.eclipse.gmf.runtime.emf.core.util.ResourceUtil.findResource(ResourceUtil.java:163)
    at com.ibm.xtools.modeler.ui.UMLModeler.openUMLResource(UMLModeler.java:1144)
    at com.ibm.xtools.modeler.ui.UMLModeler.openModelResource(UMLModeler.java:451)
    at uk.ac.open.rbacuml.dsml.plugin.research.fixing.SSoDConstraintFixingTest.loadModel(SSoDConstraintFixingTest.java:23)
    at uk.ac.open.rbacuml.dsml.plugin.research.fixing.SSoDConstraintFixingTest.testSSoDConstraintFixing(SSoDConstraintFixingTest.java:32)
    at uk.ac.open.rbacuml.dsml.plugin.research.fixing.SSoDConstraintFixingTest.main(SSoDConstraintFixingTest.java:17)
Caused by: java.lang.NullPointerException
    at org.eclipse.gmf.runtime.common.core.util.Log.<clinit>(Log.java:42)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    ... 14 more

I'm obviously doing something wrong, but I have no idea what. Any suggestions?


Solution

  • ModelResources should be opened from within the EditingDomain of the UMLModeler:

    UMLModeler.getEditingDomain().runExclusive(new Runnable() {
        public void run() {
            Element root = null;
            try {
                root = UMLModeler.openModelResource(fileName);
            } catch (IOException e) {
                System.out.println("Error while opening model " + fileName + ": " + e.getMessage());
            }
        }
    });