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

Bug 366841

Summary: [Legacy] Unidirectionnal non containment reference not properly set after commit for current client
Product: [Modeling] EMF Reporter: Steve Monnier <steve.monnier>
Component: cdo.legacyAssignee: Christian Damus <give.a.damus>
Status: NEW --- QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3 CC: alex.lagarde, Ed.Merks, laurent.redor, stepper
Version: 4.13   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
JUnit reproducing the issue none

Description Steve Monnier CLA 2011-12-15 12:30:16 EST
Build Identifier: 

I have an issue on Ecore models (Legacy mode). I have 2 EClass. I set an EClass as a super type of the other one (undirectionnal and non containment reference). After commit, the super type reference seems lost for the current client. However, it is properly committed on repository because another client can see the modification. The current user has to close and reopen his session.

Reproduced with the CDO Editor but a JUnit to reproduce is comming soon.

Thanks,
Steve

Reproducible: Always

Steps to Reproduce:
1.Create 2 EClass
2.Add a super type reference between these classes
3.Commit
Comment 1 Steve Monnier CLA 2011-12-15 12:41:16 EST
Created attachment 208457 [details]
JUnit reproducing the issue

Here is a JUnit test to reproduce the issue with 2 Eclass and a super type reference
Comment 2 Steve Monnier CLA 2012-01-03 08:52:42 EST
Happy new year! :)

Do you have any idea how to fix/work around this issue?

Thanks,
Steve
Comment 3 Martin Fluegge CLA 2012-01-03 12:45:01 EST
Sorry, I do not see any chance to have a look at this problem in the next weeks. Unfortunately it will take a while until I can care for it.

Cheers,

Martin
Comment 4 Alex Lagarde CLA 2012-01-05 04:05:40 EST
Ok, after a short investigation the problem seems to be caused by the EClass implementation.

The CDOLegacyWrapper, in the cdoInternalPreCommit() method, clears all the structural features that are unset so that no default value is stored in the database.

Here is the CDOLegacyWrapper code that fulfills this task :

for (EStructuralFeature feature : CDOModelUtil.getAllPersistentFeatures(eClass)) {
      if (feature.isUnsettable()) {
        if (!instance.eIsSet(feature)) {
          if (feature.isMany()) {
            InternalEList<Object> list = (InternalEList<Object>)instance.eGet(feature);
            clearEList(list);
          }

In the case of an EClass c1 having an EClass c2 as supertype, when we test if the "EGenericSuperTypes" of c1 is set, it returns false (see the EClassImpl.getEGenericSuperTypes() method : if the GenericSuperTypes collection does not contain any Generictype having a non-null ETypeParameter or a non-empty ETypeArguments, it returns false).

Ok, no problem here. As this feature is unset, we clear it. But clearing the EGenericSuperTypes list also clears the ESuperTypes list, so after the call to cdoPreCommit(), c1 does not have any superTypes any more.

According to me, the EGenericSuperTypes collection should not use the same list as ESuperTypes, or maybe it should be defined as derived ?

===================================================
Here his a copy of Ed Merks answer :
Things like eSuperType and eGenericSuperType are "mutually derived".  I.e., each can be derived from the other.  Which one is consider set depends on which of the two needs to be serialized.  If no use is made of generics, then the eSuperType can be serialized (to produce a serialization compatible with pre-generic Ecore).  When generics are actually used, the eGenericType must be serialized to avoid loss of information.  So only one of the two will ever be considered set, never both at once.   That affects the serializer and even the copier, because otherwise they'd need special case Ecore support or serialize/copy redundantly.  You'll have to live with this.
===================================================

Ed, I understand your answer, but the CDOLegacyWrapper code seems correct.
How should we deal with this issue ? We can always put the fix in the CDOLegacyWrapper, to add stronger condition before clearing the list, but it seems quite messy.

What do you think ?
Comment 5 Ed Merks CLA 2012-01-05 05:36:44 EST
It seems bad in general that an attempt to commit will change the state of the object.  It's not clear how this approach works with Ecore in the first place.  In some cases eSuperTypes is persisted and in others eGenericSuperTypes?  That's what XML does, but what does CDO do for this case?

As I mentioned, it's as if each is derived from the other, which is literally the implemented behavior.  Changing either changes both. They can't be out of synch. Note that they're *not* the same list; they're separate lists with differently typed objects in them.  But we can't mark them both as derived because then a copier will copy neither. Of course if we didn't have to support any kind of backward compatibility we'd have made eSuperTypes derived, or more likely not provided it at all, but such is the case for a model that's ten years old...
Comment 6 Eike Stepper CLA 2012-08-14 22:54:39 EDT
Moving all open issues to 4.2. Open bugs can be ported to 4.1 maintenance after they've been fixed in master.
Comment 7 Eike Stepper CLA 2013-06-03 05:53:57 EDT
Hi Christian, I assign this legacy mode zilla to you, just in case you're ineterested. Don't feel obliged ;-)
Comment 8 Eike Stepper CLA 2013-06-29 12:15:34 EDT
We'll try to address open problems in 4.3 (master) first and then port fixes back to 4.2.
Comment 9 Eike Stepper CLA 2015-07-14 02:16:58 EDT
Moving all open bugzillas to 4.5.
Comment 10 Eike Stepper CLA 2016-07-31 00:59:51 EDT
Moving all unaddressed bugzillas to 4.6.
Comment 11 Eike Stepper CLA 2017-12-28 01:09:37 EST
Moving all open bugs to 4.7
Comment 12 Eike Stepper CLA 2019-11-08 02:17:14 EST
Moving all unresolved issues to version 4.8-
Comment 13 Eike Stepper CLA 2019-12-13 12:43:03 EST
Moving all unresolved issues to version 4.9
Comment 14 Eike Stepper CLA 2020-12-11 10:44:42 EST
Moving to 4.13.