Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » NPE in serializer
NPE in serializer [message #900609] Tue, 07 August 2012 18:42 Go to next message
Tim Geisler is currently offline Tim Geisler
Messages: 37
Registered: July 2009
Member
Hi,

I get the following NPE when using the new serializer to serialize a model constructed by a M2M transformation. The model seems to be correct, i.e. no feature assignment is missing.

java.lang.NullPointerException
	at org.eclipse.xtext.serializer.sequencer.AbstractSyntacticSequencer.accept(AbstractSyntacticSequencer.java:104)
	at org.eclipse.xtext.serializer.sequencer.AbstractSyntacticSequencer.navigateToAbsorber(AbstractSyntacticSequencer.java:426)
	at org.eclipse.xtext.serializer.sequencer.AbstractSyntacticSequencer.navigateToAbsorber(AbstractSyntacticSequencer.java:414)
	at org.eclipse.xtext.serializer.sequencer.AbstractSyntacticSequencer.finish(AbstractSyntacticSequencer.java:346)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.finish(SequenceFeeder.java:369)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:442)
	at xxx.cml.serializer.AbstractCmlSemanticSequencer.sequence_WhenUnlessExpression(AbstractCmlSemanticSequencer.java:2308)
	at xxx.cml.serializer.AbstractCmlSemanticSequencer.createSequence(AbstractCmlSemanticSequencer.java:1084)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptAction(SequenceFeeder.java:292)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:95)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:403)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
	at xxx.cml.serializer.AbstractCmlSemanticSequencer.sequence_WhenUnlessExpression(AbstractCmlSemanticSequencer.java:2308)
	at xxx.cml.serializer.AbstractCmlSemanticSequencer.createSequence(AbstractCmlSemanticSequencer.java:1084)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:215)
	at xxx.cml.serializer.AbstractCmlSemanticSequencer.sequence_ConditionalExpression(AbstractCmlSemanticSequencer.java:1174)
	at xxx.cml.serializer.AbstractCmlSemanticSequencer.createSequence(AbstractCmlSemanticSequencer.java:257)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptAction(SequenceFeeder.java:292)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:95)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:403)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
	at xxx.cml.serializer.AbstractCmlSemanticSequencer.sequence_AdditiveExpression(AbstractCmlSemanticSequencer.java:1097)
	at xxx.cml.serializer.AbstractCmlSemanticSequencer.createSequence(AbstractCmlSemanticSequencer.java:125)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:222)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:401)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)


The relevant part of the grammar is the following:
Expression
    :   ConditionalExpression
    |   WhenUnlessExpression
    |   SwitchExpression
    ;
    
ConditionalExpression
    :   'if' condition=Expression 'then' valueIfTrue=Expression 'else' valueIfFalse=Expression
    ;
    
WhenUnlessExpression returns Expression
    :   ConditionalOrExpression ({WhenUnlessExpression.value=current} operator=('when' | 'unless') condition=Expression)?
    ;
    
SwitchExpression
    :   'switch' expression=Expression '{' (caseClauses+=CaseClause)* ('default' ':' defaultExpression=Expression) '}'
    ;
    
CaseClause
    :   'case' caseExpressions+=Expression (':' 'case' caseExpressions+=Expression)* ':' valueExpression=Expression
    ;
    
ConditionalOrExpression returns Expression
    :   ConditionalAndExpression ({ConditionalOrExpression.left=current} operator='||' right=ConditionalAndExpression)*
    ;

... // left out

Primary returns Expression
    :   ParenthesizedExpression
    |   Literal
... // left out
    ;   
    
ParenthesizedExpression returns Expression
	:	'(' Expression ')'
	;


The mysterious issue is that this problem only occurs if two WhenUnlessExpression objects are nested (you can see this in the stack trace).

Are there any ideas on how to fix this problem? Is there an alternative formulation of the grammar for which the serializer is successful?

How to adapt the serializer? I guess sequence_WhenUnlessExpression will have to be adapted. But how?

I'd appreciate any hints on how to fix this problem.

Best regards,

Tim
Re: NPE in serializer [message #925356 is a reply to message #900609] Thu, 27 September 2012 16:42 Go to previous messageGo to next message
Tim Geisler is currently offline Tim Geisler
Messages: 37
Registered: July 2009
Member
Hi all,

unfortunately, I was today encountered with another instance of my still unsolved problem.

Are there any Xtext serializer 2.0 experts who could give me some hint?

Best regards,

Tim
Re: NPE in serializer [message #925372 is a reply to message #925356] Thu, 27 September 2012 17:00 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2500
Registered: July 2009
Senior Member
On 2012-27-09 9:42, Tim Geisler wrote:
> Hi all,
>
> unfortunately, I was today encountered with another instance of my still
> unsolved problem.
>
> Are there any Xtext serializer 2.0 experts who could give me some hint?
>
> Best regards,
>
> Tim
It is quite complicated - you could try overriding:
AbstractCmlSemanticSequencer.sequence_WhenUnlessExpression

And then return what you want returned instead of what is automatically
generated. But that is as much help as I can give you (I am not an expert).

Be prepared to hone your debugging skills and figure out what it is
doing wrong (and what it is supposed to do). Not easy though to debug
backtracking.

One option is to fix the grammar so it does not need backtracking, but
that can be complicated (or close to impossible depending on the language).

Think the experts are busy with JavaOne...

- henrik
Re: NPE in serializer [message #925425 is a reply to message #925372] Thu, 27 September 2012 17:56 Go to previous message
Tim Geisler is currently offline Tim Geisler
Messages: 37
Registered: July 2009
Member
Hi Henrik,

thanks for your quick answer.

BTW, I should have enough experience in debugging backtracking from a former live with Prolog and Haskell programming some time ago.

The problem for me is really to find out "what it is supposed to do" - there really should be (some more | any) documentation.

The parser for the grammar does not need backtracking. With the unparser / serializer, I am not sure whether backtracking is required. It is difficult to change the grammar since the language is in productive use - so a change in the grammar rules must not change the language itself.

Best regards,

Tim
Previous Topic:Scope for starting element
Next Topic:Serialize models containing cross-references
Goto Forum:
  


Current Time: Fri Oct 24 07:23:24 GMT 2014

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

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