Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 356911 - [resource description] exclude dangling references
Summary: [resource description] exclude dangling references
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.1.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: SR2   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-07 06:47 EDT by Knut Wannheden CLA
Modified: 2017-09-19 17:29 EDT (History)
3 users (show)

See Also:
sven.efftinge: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Knut Wannheden CLA 2011-09-07 06:47:19 EDT
I think it would make sense if the method DefaultResourceDescriptionStrategy#isResolvedAndExternal(EObject, EObject) would also check if the target object is an non contained object. I.e. in case it is not a proxy check that it actually has an non null eResource(). It doesn't make sense to export dangling references.

This problem should actually be caught during validation, but at that point it is already too late. The reference has already been added to the builder state.

So I propose to change:

	protected boolean isResolvedAndExternal(EObject from, EObject to) {
		if (to == null)
			return false;
		if (!to.eIsProxy())
			return from.eResource() != to.eResource();

		return !getLazyURIEncoder()
				.isCrossLinkFragment(from.eResource(), ((InternalEObject) to).eProxyURI().fragment());
	}

to:

	protected boolean isResolvedAndExternal(EObject from, EObject to) {
		if (to == null)
			return false;
		if (!to.eIsProxy()) {
			if (to.eResource() == null) {
				LOG.error("Reference from " + EcoreUtil.getURI(from) + " to " + to + " cannot be exported as the target is not contained in a resource.");
				return false;
			}
			return from.eResource() != to.eResource();
		}
		return !getLazyURIEncoder()
				.isCrossLinkFragment(from.eResource(), ((InternalEObject) to).eProxyURI().fragment());
	}
Comment 1 Sven Efftinge CLA 2011-09-07 10:04:00 EDT
+1
Comment 2 Jan Koehnlein CLA 2011-09-07 10:16:20 EDT
+1
Comment 3 Sebastian Zarnekow CLA 2011-09-07 13:35:00 EDT
I wonder where the dangling references come from in the first place. However, since the cannot provide reasonable uris it's a good idea to filter them.
Comment 4 Knut Wannheden CLA 2011-09-07 15:36:34 EDT
The use case is admittedly a bit dubious: A derived reference which in its implementation returned on-the-fly created EObjects, which weren't contained anywhere. Additionally the default EObjectValidator which checks for this kind of problem (in validate_EveryReferenceIsContained()) was disabled for performance reasons.

I believe that this kind of error should only be possible if the language implementor has done something wrong. Not because of a mistake of the user. That's why we also decided to disable this validation as it has a nasty side effect: It causes all proxies, which we've been so careful to maintain, to be resolved.

The additional check and logged error in isResolvedAndExternal() thus also doubles as a substitute for the validation. An alternative would of course be to modify the validation to only emit diagnostics for this specific case; without resolving any proxies.
Comment 5 Sven Efftinge CLA 2011-09-08 03:15:33 EDT
The additional guard as proposed is perfectly ok.
Comment 6 Knut Wannheden CLA 2011-09-19 10:12:32 EDT
Pushed fix to master.
Comment 7 Karsten Thoms CLA 2017-09-19 17:17:50 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 8 Karsten Thoms CLA 2017-09-19 17:29:10 EDT
Closing all bugs that were set to RESOLVED before Neon.0