Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Could not serialize EObject via backtracking(RuntimeException appears to be caused by rule order)
Could not serialize EObject via backtracking [message #1388800] Fri, 27 June 2014 00:26 Go to next message
Jack Greenfield is currently offline Jack GreenfieldFriend
Messages: 18
Registered: June 2014
Junior Member
I'm getting the following exception when serializing a GMF diagram to an XText resource:

java.lang.RuntimeException: Could not serialize EObject via backtracking.
Constraint: null name=ID extends=[System|QualifiedName]? description=STRING? (properties+=Property properties+=Property*)? (annotations+=Annotation annotations+=Annotation*)? (metrics+=MetricGroup metrics+=MetricGroup*)? (constraints+=ConstraintGroup constraints+=ConstraintGroup*)? (elements+=Resource elements+=Resource*)? (elements+=Package elements+=Package*)? (elements+=Contract elements+=Contract*)? (connectors+=ProviderEndpoint connectors+=ProviderEndpoint*)? (connectors+=ConsumerEndpoint connectors+=ConsumerEndpoint*)? (relationships+=Dependency relationships+=Dependency*)? (relationships+=Relationship relationships+=Relationship*)? elements+=Component* null
Values: name(1), connectors(2)
Semantic Object: Model'org.example.model'.elements[0]->System'System1'
Context: Component

The xtext grammar and the GMF editor were developed independently, so both are of non trivial size. However, the salient piece of the grammar, from what I can tell, is as follows:

System returns system::System:
{system::System}
'system' name=ID ('extends' extends=[system::System|QualifiedName])? (description=STRING)?
('{'
('providers' '{' connectors+=ProviderEndpoint (',' connectors+=ProviderEndpoint)* '}')?
('consumers' '{' connectors+=ConsumerEndpoint (',' connectors+=ConsumerEndpoint)* '}')?
(elements+=Component)*
'}')?;

I've removed a few of the productions, since they aren't necessary to recreate the problem. So, here's the problem...

If I create a System and add first a ProviderEndpoint, then a ConsumerEndpoint, all is well, and the serialization looks like this:

package org.example.model {
system System1 {
providers {
< System1Proxy1
}
consumers {
> System1Proxy2
}
}
}

However, if I create a System and add first a ConsumerEndpoint, then a ProviderEndpoint, I get the exception shown above. A (perhaps overly) simple reading of the situation suggests that order matters, and that the serializer is having trouble writing to parts of the file that should precede parts already written.

It's easy to recreate the problem with other parts of the grammar where a container has an ordered list of contents by likewise first adding something that must come later in the serialization, and then adding something that must come earlier.

I tried adding a fragment provider, as follows:

public class LanguageFragmentProvider implements IFragmentProvider {
@Override
public String getFragment(EObject obj, Fallback fallback) {
String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj);
if (obj instanceof Model) {
return name;
} else if (obj instanceof Element) {
EObject container = obj.eContainer();
if (container != null && !(container instanceof Model)) {
String containerName = SimpleAttributeResolver.NAME_RESOLVER
.apply(container);
return containerName + "." + name;
}
}
return fallback.getFragment(obj);
}

@Override
public EObject getEObject(Resource resource, String fragment,
Fallback fallback) {
for (TreeIterator<EObject> allContents = resource.getAllContents(); allContents
.hasNext() ; ) {
EObject next = allContents.next();
if (fragment.equals(getFragment(next, fallback))) {
return next;
}
}

return fallback.getEObject(fragment);
}
}

And I've verified that it's getting called and producing the right results. As for scoping, I'm using the following fragments in the MWE2 workflow:

// scoping and exporting API
fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
fragment = exporting.QualifiedNamesFragment auto-inject {}

Any idea what might be causing the problem and/or how to work around it?
Thanks.







[Updated on: Fri, 27 June 2014 00:27]

Report message to a moderator

Re: Could not serialize EObject via backtracking [message #1388851 is a reply to message #1388800] Fri, 27 June 2014 02:27 Go to previous messageGo to next message
Jack Greenfield is currently offline Jack GreenfieldFriend
Messages: 18
Registered: June 2014
Junior Member
I've reorganized the grammar so that the clauses can be unordered. That solves the backtracking problem, but introduces a duplication problem. Note the repetition of the connections section. There should be just one connections section containing 3 connections.

connections {
System1Proxy1App2Service1 (System1.System1Proxy1 = System1.App2.App2Service1)
}
dependencies {
App2Resource3 Resource3 = App2 {
none
}
}
connections {
System1Proxy2FrontEndSite1 (System1.System1Proxy2 <
System1.FrontEnd.FrontEndSite1)
}
connections {
FrontEndClient2App2Service1 (System1.FrontEnd.FrontEndClient2 =
System1.App2.App2Service1)
}
Re: Could not serialize EObject via backtracking [message #1388923 is a reply to message #1388851] Fri, 27 June 2014 05:15 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 246
Registered: June 2013
Senior Member
Have you tried to use "&" instead of the "|" to specify your unordered group?
As the documentation says, this still allows only one instance is allowed per type.
Re: Could not serialize EObject via backtracking [message #1389190 is a reply to message #1388923] Fri, 27 June 2014 13:05 Go to previous message
Jack Greenfield is currently offline Jack GreenfieldFriend
Messages: 18
Registered: June 2014
Junior Member
I did use & to join the clauses. Was surprised to see them repeated, given that only one should be allowed per the documentation, to your point. Sadly, the parser enforces the constraint, and flags the repeated elements as errors.

So, the point here is that the hard contract for serialization mentioned throughout the documentation is violated... The serializer writes a model that cannot be parsed.

[Updated on: Fri, 27 June 2014 15:24]

Report message to a moderator

Previous Topic:QualifiedNameProvider simply using URI, bad / OK?
Next Topic:Best way of traversing a model: bottom up
Goto Forum:
  


Current Time: Thu Dec 12 07:00:37 GMT 2019

Powered by FUDForum. Page generated in 0.01505 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top