Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 298678 - cross resource containment and validation
Summary: cross resource containment and validation
Status: VERIFIED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ed Merks CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 286329
  Show dependency tree
 
Reported: 2009-12-31 08:27 EST by Simon Bernard CLA
Modified: 2010-05-04 08:17 EDT (History)
2 users (show)

See Also:


Attachments
Patches to address the issue (22.74 KB, patch)
2010-02-09 16:50 EST, Ed Merks CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Bernard CLA 2009-12-31 08:27:49 EST
Build Identifier: 

I have 2 problems with emf validation because I use cross resource containment.

  1) When you have cross containment resource, you can have objects which contain objets which are proxy, but the validation don't verify that the object which will validate is a proxy or not.. so a lot of errors are raised but not really relevant. (ex : a feature with an empty value)

  2) Unresolve proxy are not detected because the method "validate_EveryProxyResolves" of EObjectValidor verify only proxy on reference but not in containement. 

Reproducible: Always
Comment 1 Simon Bernard CLA 2009-12-31 08:28:21 EST
I propose two solution :
========================
1) add a test to verify that the objet is not a proxy before to validate it in the validator generated by EMF.

/**
* Calls <code>validateXXX</code> for the corresponding classifier of the
* model. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
protected boolean validate(int classifierID, Object value, DiagnosticChain diagnostics, Map<Object, Object> context)
{
   if (value instanceof EObject && ((EObject) value).eIsProxy())
    return true;

   switch (classifierID)
   {
    case MyPackage.MY_OBJECT:
        return validateMYOBJECT((MyObject) value,     diagnostics, context);
     .... ....
   }
}


2)In EObjectValidator add test through containment to the "validate_EveryProxyResolves" :
for (EObject content : eObject.eContents())
{
   if (content.eIsProxy())
   {
      result &= false;
      if (diagnostics != null)
      {
            diagnostics.add(createDiagnostic(Diagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_PROXY_RESOLVES, _UI_UnresolvedProxy_diagnostic", new Object[] { getFeatureLabel(content.eContainingFeature(), context),         getObjectLabel(eObject, context),                        getObjectLabel(content, context) }, new Object[] { eObject,            content.eContainingFeature(), content }, context));
       }
       else
       {
          break;
       }
     }
}
Comment 2 Ed Merks CLA 2010-02-09 16:50:18 EST
Created attachment 158643 [details]
Patches to address the issue

This approach is less expensive than iterating over the contents a second time.  When creating a test case with a broken proxy reference from an EPackage to an EClass I noticed that I screwed of the past year by not keeping the ValidatorClass template in sync with the new default constraints that were added; I needed to regenerate Ecore with the updated patterns.
Comment 3 Ed Merks CLA 2010-02-09 16:57:25 EST
Oh yes, I wondered too about validation of container references, so I have some logic for that.  But then I wondered what if there isn't an explicit container reference but there's still a proxy.  It's a bit hard to get into this state; the container would need to be in a different resource, that resource would need to be unloaded, and then the resource would need to be deleted or corrupted...
Comment 4 Ed Merks CLA 2010-02-09 16:57:55 EST
Dave do you have any opinions on this?
Comment 5 Ed Merks CLA 2010-02-19 14:58:21 EST
If there are no opinions to share, I'll just do what I think seems best.
Comment 6 Ed Merks CLA 2010-03-01 12:49:47 EST
The fix is committed to CVS for 2.6.
Comment 7 Ed Merks CLA 2010-05-04 08:17:41 EDT
The fixes are available in 2.6 M7 or earlier.