Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313491 - Unsafe type comparison when deciding which checks apply in a given context
Summary: Unsafe type comparison when deciding which checks apply in a given context
Status: CLOSED WONTFIX
Alias: None
Product: M2T
Classification: Modeling
Component: Xpand (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-19 05:23 EDT by marc.schlienger CLA
Modified: 2020-04-30 13:54 EDT (History)
0 users

See Also:


Attachments
Workaround (696 bytes, patch)
2010-05-19 05:27 EDT, marc.schlienger CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description marc.schlienger CLA 2010-05-19 05:23:20 EDT
Build Identifier: org.eclipse.xtend_0.7.2.v200908120436

When you run various workflows within the same JVM at different point in time, but within the same application context, the checks (model validation) will not be applied if the metamodel they rely on has been configured more than once. Let me explain this with pseudo-code:

given:
transformER2Ecore() calls workflow_1
generateCodeInternal() calls workflow_2

generate() calls transformER2Ecore() and then generateCodeInternal()

NB: the separation in two workflows makes sense, I can explain why if required.

workflow_1:
<bean id="mm" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
   <metaModelFile value="my/package/mm.ecore"/>
</bean>
<component class="">
  <metaModel idRef="mm" />
   ... do some transformation
</component>
<component class="org.eclipse.emf.mwe.utils.Writer">
   <uri value="my_file"/>
   <modelSlot value="model" />
</component>

workflow_2:
<bean id="mm" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
   <metaModelFile value="my/package/mm.ecore"/>
</bean>
<component class="org.eclipse.emf.mwe.utils.Reader">
   <uri value="my_file"/>
   <modelSlot value="model" />
</component>
<component class="org.eclipse.xtend.check.CheckComponent">
   <metaModel idRef="mm"/>
   <checkFile value="my_check_file"/>
   <emfAllChildrenSlot value="model" />
</component>
...


The checks in the second workflow won't be applied, never! This is due to the fact that the EMF metamodel is instanciated twice, but Check.validate() on line 149 "if (typeToCheck.isInstance(o))" will lead to the call of EClassifierImpl.dynamicIsInstance() when working with dynamic Ecore, which looks like this:

  protected boolean dynamicIsInstance(EObject eObject)
  {
    return eObject.eClass() == this;
  }

As you can see, == is used, but two different instances of the same metamodel are actually compared. Hence, it will eventually return false and the checks won't be applied.

We could implement a workaround (see attachment) by using a patched version of org.eclipse.xtend.typesystem.emf.EmfMetaModel which always takes the metamodel from the EPackage registry if there is one applicable for the given Namespace URI.

We then simply use this metamodel in the workflow and it works for us (see the "2" in the class name of the EmfMetaModel):

workflow_2:
<bean id="mm" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel2">
   <metaModelFile value="my/package/mm.ecore"/>
</bean>


A better solution would be to adjust the behaviour in EcoreUtil2.getEPackage() and registerEPackage(): if an epackage is already registered in EPackage.Registry, the method should always return the one found in the registry instead of the current one just registered (of course, the first time an epackage is registered, it is the same).


Reproducible: Always

Steps to Reproduce:
(see description above)
1. use two or more separate workflow in the same JVM
2. having same metmodels configured more than once
3. the checks of one of the following workflows will not be applied
Comment 1 marc.schlienger CLA 2010-05-19 05:27:21 EDT
Created attachment 169076 [details]
Workaround
Comment 2 Karsten Thoms CLA 2020-04-30 13:54:47 EDT
This is a batch close of open M2T Xpand bugs. It is not planned work on this component in the foreseeable future. If you think this issue needs to be solved and you plan to contribute a fix then feel free to reopen it.