Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354736 - Unable to create EObject from dynamic EClass which extends generated abstract EClass
Summary: Unable to create EObject from dynamic EClass which extends generated abstract...
Status: RESOLVED WONTFIX
Alias: None
Product: EMF
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ed Merks CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-15 10:50 EDT by Krasimir Chobantonov CLA
Modified: 2011-08-15 13:14 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Krasimir Chobantonov CLA 2011-08-15 10:50:18 EDT
Build Identifier: 2.5, 2.6., 2.7

When we have a dynamic EPackage with a dynamic EClass that extends generated abstract EClsss then the EFactoryImpl.create(EClass) method will be executed which will check if any of the super classes has not null getInstanceClass which in this case will return not null but the class is actually abstract and when trying to create the new instance it will fail - we need to change the if statement on line 247 from 

      if (eSuperType.getInstanceClass() != null)

to 
      if (eSuperType.getInstanceClass() != null && !eSuperType.isAbstract())
 

Reproducible: Always

Steps to Reproduce:
1. Create a new EMF model with an abstract EClass
2. Generate the code for the EMF model at step 1
3. Dynamically create a new EPackage and then a new EClass inside the EPackage and  add the generated abstract EClass as super class of the dynamic EClass - try to create a new EObject instance from the dynamic EClass
Comment 1 Ed Merks CLA 2011-08-15 11:41:17 EDT
It's a fundamental limitation.  Multiple inheritance from generated classes isn't supported either for the same reason.  That is, in all cases, it must be possible to create an instance that implements all the generated interfaces involved.  That's only possible if you can create an instance of the corresponding generated class (and there's only of of them).
Comment 2 Krasimir Chobantonov CLA 2011-08-15 12:34:58 EDT
Ed,

Thanks for the quick reply. So isn't it possible at least to do that when we have only one super class ? then it should be possible to do that correct ?

I do see that there might be a problem when you have a dynamic EClass that extends  multiple EClass-es but what in case we do have only one? Currently the use case of having a dynamic EClass that extends abstract generated EClass is not supported at all - at least having only one such class shouldn't be a problem to do that correct ?

Krasimir
Comment 3 Ed Merks CLA 2011-08-15 12:44:29 EDT
As I said, we must be able to create an implementation class that implements all the generated interfaces because the instance can be passed to the generated framework's methods and that instance can be cast to any expected generated interface).  So what can we create if the base class is abstract?  Nothing...
Comment 4 Krasimir Chobantonov CLA 2011-08-15 13:14:27 EDT
Ed,

Now it is clear why you object and I agree that if you do that then there might be cases when the code will fail with RuntimeException because of the cast - but currently the code will fail anyway when trying to create the EObject and also if your method that operates with the instance are checking if it does implement interface using the EMF reflection framework instead of Java then this will work.

Anyway I see your point. 
Krasimir