Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 357813

Summary: [M2x IDE Integration] Risk of NullPointerException when transforming models using M2MConfigurationWizard
Product: [Automotive] Sphinx Reporter: Stephan Eberle <stephaneberle9>
Component: CoreAssignee: Stephan Eberle <stephaneberle9>
Status: CLOSED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: ali.akar82, idydieng, imran.ar
Version: 0.7.0   
Target Milestone: 0.7.0   
Hardware: All   
OS: All   
Whiteboard:

Description Stephan Eberle CLA 2011-09-15 10:15:48 EDT
When transforming models whole metamodel classes have a deep inheritance hierarchy (e.g., Artop AUTOSAR metamodel but Sphinx Hummingbird metamodel) and using the org.eclipse.sphinx.xtendxpand.ui.wizards.M2MConfigurationWizard for invoking the transformation, the following NPE is likely to happen:

java.lang.NullPointerException
	at org.eclipse.xtend.typesystem.AbstractTypeImpl.isAssignableFrom(AbstractTypeImpl.java:158)
	at org.eclipse.internal.xtend.type.baseimpl.TypesComparator.compare(TypesComparator.java:37)
	at org.eclipse.internal.xtend.type.baseimpl.TypesComparator.compare(TypesComparator.java:1)
	at org.eclipse.internal.xtend.type.baseimpl.PolymorphicResolver.getFeature(PolymorphicResolver.java:81)
	at org.eclipse.internal.xtend.type.baseimpl.PolymorphicResolver.getExtension(PolymorphicResolver.java:56)
	at org.eclipse.xtend.expression.ExecutionContextImpl$1.createNew(ExecutionContextImpl.java:347)
	at org.eclipse.xtend.expression.ExecutionContextImpl$1.createNew(ExecutionContextImpl.java:1)
	at org.eclipse.internal.xtend.util.Cache.get(Cache.java:26)
	at org.eclipse.xtend.expression.ExecutionContextImpl.getExtensionForTypes(ExecutionContextImpl.java:352)
	at org.eclipse.xtend.expression.ExecutionContextImpl.getExtension(ExecutionContextImpl.java:361)
	at org.eclipse.xtend.XtendFacade.call(XtendFacade.java:92)
	at org.eclipse.sphinx.xtendxpand.jobs.XtendJob$1.run(XtendJob.java:294)
	at org.eclipse.sphinx.emf.util.WorkspaceTransactionUtil$1.doExecute(WorkspaceTransactionUtil.java:175)
	at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:513)
	at org.eclipse.sphinx.emf.util.WorkspaceTransactionUtil.executeInWriteTransaction(WorkspaceTransactionUtil.java:192)
	at org.eclipse.sphinx.xtendxpand.jobs.XtendJob.run(XtendJob.java:309)
	at org.eclipse.sphinx.xtendxpand.ui.wizards.M2MConfigurationWizard$1.run(M2MConfigurationWizard.java:131)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 1 Stephan Eberle CLA 2011-09-17 02:38:30 EDT
= Problem analysis =
When the user has selected a model to model transformation action (i.e., a subclass of BasicM2MAction) and the M2MConfigurationWizard opens up, she or he can select the Xtend template to use and one of the applicable Xtend functions inside. In order to retrieve the latter and populate the corresponding combo list, ExtensionGroup#createFunctionFieldItems(List<Extension> extensions) calls into the Xtend runtime. Once the user has completed all configuration choices and clicks the finish button, the model to model transformation is started by scheduling the XtendJob which in turn calls again the Xtend runtime, namely the Xtend facade.

However, there is a critical difference between the 2 code fragments using the Xtend runtime. While the XtendJob sets up an ExecutionContextImpl with a TypeSystemImpl that holds and properly initializes the Xtend MetaModels to be used, the ExtensionGroup attemps to use the Xtend MetaModels directly, i.e., without setting up a wrapping TypeSystemImpl. This entails that the Xtend MetaModels are only partially initialized, in particular the EmfRegistryMetaModel (or any MetaModel derived from it). Here, the EmfRegistryMetaModel.setTypeSystem(TypeSystem) method gets never called and consequently the the Xtend type for EObject which is used as super type for the Xtend types of all EClasses in the underlying Ecore doesn't get instantiated and remains null. While this problem does not disturb the retreival of the Xtend functions in the Xtend template, the Xtend types including their null super type are anyway cached in the EmfRegistryMetaModel instance. So, they are still there when the same EmfRegistryMetaModel instance is again used in the XtendJob and then cause the NullPointerException documented in the description of this bug.

= Resolution proposal =
* Setup a TypeSystemImpl wrapping the Xtend MetaModels being used in the constructor of the M2MConfigurationWizard
* Hand this TypeSystemImpl through to both the ExtensionGroup for upfront retrieval of Xtend functions from the selected Xtend template as well as CheckJob and XtendJob for running the model to model transformation
** Replace metaModels constructor parameter/field by typeSystem parameter/field in XtendConfigurationPage and ExtensionGroup
** Add extra constructors with typeSystem parameter to XtendJob
* Make the corresponding changes in M2TConfigurationWizard, XpandConfigurationPage, TemplateGroup, and XpandJob
Comment 2 Stephan Eberle CLA 2011-09-19 05:05:06 EDT
Fixed as proposed in comment #1.
Comment 3 Balazs Grill CLA 2021-07-14 02:14:49 EDT
Mass-closing Resolved tickets