| Summary: | Return value of eContainingFeature from CDORevision seems incorrect | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Modeling] EMF | Reporter: | kaab <kaabab> | ||||||||
| Component: | cdo.core | Assignee: | Eike Stepper <stepper> | ||||||||
| Status: | CLOSED WORKSFORME | QA Contact: | Eike Stepper <stepper> | ||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | ||||||||||
| Version: | 4.1 | ||||||||||
| Target Milestone: | --- | ||||||||||
| Hardware: | PC | ||||||||||
| OS: | Linux | ||||||||||
| Whiteboard: | |||||||||||
| Attachments: |
|
||||||||||
|
Description
kaab
Created attachment 198648 [details]
Unit Test showing the assertion failure
Created attachment 198649 [details]
Ecore Model Used in test to reproduce the issue
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).
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.
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, You're welcome. I've also added respective JavaDoc to CDORevisionData.getContainingFeatureID() to make it harder to run into this trap in the future ;-) Closing. |