Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333022 - [serializer] Serializer should be able to re-serialize resources with link errors
Summary: [serializer] Serializer should be able to re-serialize resources with link er...
Status: VERIFIED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: v2.6
Keywords:
Depends on: 333976
Blocks:
  Show dependency tree
 
Reported: 2010-12-21 10:04 EST by Jan Koehnlein CLA
Modified: 2014-05-20 07:55 EDT (History)
5 users (show)

See Also:


Attachments
Test reproducing the error condition (1.16 KB, text/plain)
2010-12-21 10:05 EST, Jan Koehnlein CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Koehnlein CLA 2010-12-21 10:04:16 EST
If a resource has had a unresolved cross-ref when it was loaded, the serializer should be able to re-serialize that cross-ref using the node model information.
Comment 1 Jan Koehnlein CLA 2010-12-21 10:05:48 EST
Created attachment 185639 [details]
Test reproducing the error condition

Attached a test.
Comment 2 Moritz Eysholdt CLA 2011-01-11 09:45:32 EST
check if this depends on bug 333976. It does, if the INode is not correctly identified for the cross reference's token.
Comment 3 Sven Efftinge CLA 2012-11-19 08:45:43 EST
I think this has been fixed in the meantime.
Comment 4 Stephan Herrmann CLA 2014-02-28 10:05:40 EST
While debugging a quickfix situation in Xtext 2.4.3 I still see this bug:


Model A
  Element B
   ref |X

  Element C
   ref X

I have a quickfix for creating the unresolved element X, invoked at "|". The quickfix fails with "Could not serialize EObject via backtracking...".

If I remove the second unresolved ref in Element C the quickfix works as desired.

If s.t. has been fixed in this area, could you provide a pointer to the change so I can check why the fix doesn't help in my case?

In my case failure starts at AssignmentFinder.findValidAssignmentsForCrossRef (where it calls crossRefSerializer.isValid()). Since isValid() answers false for the unresolved proxy, we end up with no result and I couldn't see anybody up the call chain gracefully handling this situation.
Comment 5 Moritz Eysholdt CLA 2014-03-03 11:17:04 EST
isValid() should only answer with false if no node from the NodeModel has been found for the cross reference. 

The node is required because it holds the textual representation of the cross reference as seen by the parser at the time of the last parse.

Is it the case for you that no node has been found?

see: http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/plugins/org.eclipse.xtext/src/org/eclipse/xtext/serializer/tokens/CrossReferenceSerializer.java?id=v2.4.3
Comment 6 Stephan Herrmann CLA 2014-03-03 11:46:12 EST
Hi Moritz,

thanks for looking into this.

Indeed node is null, and here is why:

In this call stack:

AssignmentFinder.findValidAssignmentsForCrossRef(EObject, Iterable<AbstractElement>, EObject, INode) line: 100	
AssignmentFinder.findAssignmentsByValue(EObject, Iterable<AbstractElement>, Object, INode) line: 73	
ContextFinder.findAssignedElements(EObject, EStructuralFeature, Iterable<AbstractElement>) line: 73	

we're called from

return assignmentFinder.findAssignmentsByValue(obj, candidates, value, null);

Do you see the null, I'm seeing?
Comment 7 Stephan Herrmann CLA 2014-03-31 09:10:34 EDT
(In reply to Stephan Herrmann from comment #6)
> we're called from
> 
> return assignmentFinder.findAssignmentsByValue(obj, candidates, value, null);
> 
> Do you see the null, I'm seeing?

Should've said: this call is in ContextFinder.findAssignedElements(..)

Is there a way I can avoid this call, or work around the null in some way?
Comment 8 Moritz Eysholdt CLA 2014-04-01 12:04:17 EDT
I'm on it.
Comment 9 Moritz Eysholdt CLA 2014-04-07 05:33:19 EDT
pushed a fix to gerrit:
https://git.eclipse.org/r/#/c/24527/

As a workaround without upgrading/waiting for Xtext 2.6, you can subclass org.eclipse.xtext.serializer.sequencer.ContextFinder and bind your own implementation in the RuntimeModule.

Your own implementation of ContextFinder would need to contain the changes from the commit I'm mentioning above.
Comment 11 Stefan Oehme CLA 2014-05-14 08:59:18 EDT
Stephan, do you have a little spare time to verify this works? =)
Comment 12 Stephan Herrmann CLA 2014-05-14 12:54:38 EDT
(In reply to Stefan Oehme from comment #11)
> Stephan, do you have a little spare time to verify this works? =)

I do plan to try it soon (using the sub-classing approach from comment 9), I just need to squeeze it into a super busy schedule ... I'll let you know ... (after RC1 +0 things *should* calm down to some degree, I hope ...).

Are we slipping any Xtext code freeze deadline these days?
Comment 13 Sven Efftinge CLA 2014-05-14 15:35:48 EDT
The 2.6.0 release will be next Wednesday.
In case there's still an issue here, it could be fixed in 2.6.1 (planned for early June).
Comment 14 Stephan Herrmann CLA 2014-05-19 13:39:58 EDT
I finally found the time to adopt the solution (following the recommendation in comment 9), and: Yes, it works!

Thanks a lot, Moritz!
Comment 15 Stefan Oehme CLA 2014-05-20 01:54:47 EDT
Thanks, Stephan.