Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350447 - Return value of eContainingFeature from CDORevision seems incorrect
Summary: Return value of eContainingFeature from CDORevision seems incorrect
Status: CLOSED WORKSFORME
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.core (show other bugs)
Version: 4.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Eike Stepper CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-27 09:49 EDT by kaab CLA
Modified: 2012-09-21 07:17 EDT (History)
0 users

See Also:


Attachments
Unit Test showing the assertion failure (5.86 KB, text/x-java)
2011-06-27 09:49 EDT, kaab CLA
no flags Details
Ecore Model Used in test to reproduce the issue (2.19 KB, application/octet-stream)
2011-06-27 09:50 EDT, kaab CLA
no flags Details
test v2 (6.85 KB, text/plain)
2011-07-03 06:34 EDT, Eike Stepper CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description kaab CLA 2011-06-27 09:49:17 EDT
Build Identifier:  I20110613-1736

+ This was first reported in the forum : http://www.eclipse.org/forums/index.php/m/687581/#msg_687581

+ The issue is that the return value here is different from the expected return value (codeElement) as asserted by the test case.

+ This was tested using CDO 4.0

Reproducible: Always

Steps to Reproduce:
1. Download latest eclipse build (3.7)
2. Install EMF and CDO SDK from (latest from indigo update site)
3. Setup a project where the ecore model attached code could be generated (kdm-1.0.ecore), generate model code
4. Setup and run the unit test provided with the bug report
5. The unit test asserts that the feature retrieved using eContainingFeature is the same when retrieved from the EObject and from the CDO Revision, here the test fails with Comparison failure :
org.junit.ComparisonFailure: expected:<[codeElement]> but was:<[module]>.
Given the definition provided by Eike in the previous forum entry, my understanding is that this test should pass.
Comment 1 kaab CLA 2011-06-27 09:49:55 EDT
Created attachment 198648 [details]
Unit Test showing the assertion failure
Comment 2 kaab CLA 2011-06-27 09:50:31 EDT
Created attachment 198649 [details]
Ecore Model Used in test to reproduce the issue
Comment 3 Eike Stepper CLA 2011-07-03 06:32:52 EDT
After a while I was able to run your test and reproduce your failure. This failure is caused by wrong usage of the containingFeatureId. The correct interpretation can be found in BasicEObjectImpl.eContainingFeature() and I've rewritten your code to:

    EStructuralFeature feature = containingFeatureId <= InternalEObject.EOPPOSITE_FEATURE_BASE ?
        container.getEClass().getEStructuralFeature(InternalEObject.EOPPOSITE_FEATURE_BASE - containingFeatureId) :
        ((EReference)revision.getEClass().getEStructuralFeature(containingFeatureId)).getEOpposite();

With this code the test passes. If you want to know why exactly EMF stores/interprets this value in this particular way you may want to ask Ed (either cc him here or ask in the newsgroup).
Comment 4 Eike Stepper CLA 2011-07-03 06:34:26 EDT
Created attachment 199007 [details]
test v2

This is a passing version that also has some other enhancements that you may want to study by comparing to your original version.
Comment 5 kaab CLA 2011-07-04 10:44:59 EDT
It seems close to what I suspected but did not go trough the code in BasicEObjectImpl, which clarifies things a lot. Thanks for reply and worthful comments.

Cheers,
Comment 6 Eike Stepper CLA 2011-07-04 13:13:08 EDT
You're welcome.

I've also added respective JavaDoc to CDORevisionData.getContainingFeatureID() to make it harder to run into this trap in the future ;-)
Comment 7 Eike Stepper CLA 2012-09-21 07:17:05 EDT
Closing.