Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 312316

Summary: Cannot serialize object with leading optional null element
Product: [Modeling] TMF Reporter: Sebastian Zarnekow <sebastian.zarnekow>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: critical    
Priority: P3 Flags: sebastian.zarnekow: helios+
Version: 1.0.0   
Target Milestone: RC1   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Sebastian Zarnekow CLA 2010-05-10 14:14:15 EDT
When applying a quick fix serialization fails for "documentation" (or so I interpret the message).

With this grammar:
----
Repository returns build::Repository : {build::Repository}
      (documentation = DOCUMENTATION)?
      handlerType = ID
      name = ID
      '{'
          (
            ("remote" '=' remote = URI ';')?
          & ("local" '=' local = URI ';')?
          & ("user" '=' user = STRING ';')?
          & ("password" '=' password = STRING ';')?
          & ("branches" branches += Branch (',' branches += Branch)* ';')?
          & ("options" '{' (options += RepoOption)+ '}' )?
          )
      '}'
    ;

And this input:
---
  cvs TestRepo {
  local = "file://aLocalURL/";
  user = "hello";
  password = "hush-hush";
  }

I have a validation rule that checks that "remote" is set to a URI. And a quick fix associated with this error.
When applying the quickfix...

This is what I get:
---
org.eclipse.emf.common.util.WrappedException: org.eclipse.xtext.parsetree.reconstr.XtextSerializationException: Serialization failed
<# of serialized tokens>: <EObject path> "<serializable fragment, starting from the end>":
  -> <possible reasons for not continuing>
26:BeeModel.buildUnits[0]->BuildUnit'aTestUnit'.repositories[0]->Repository'TestRepo': "cvs TestRepo { local = "file://aLocalURL/" ; remote...":
  -> Repository_DocumentationAssignment_1: Repository.documentation is not set.
  -> Repository_RepositoryAction_0: n/a
21:BeeModel.buildUnits[0]->BuildUnit'aTestUnit'.repositories[0]->Repository'TestRepo': "cvs TestRepo { remote = "http://abc.org" ; user = "...":
  -> Repository_DocumentationAssignment_1: Repository.documentation is not set.
  -> Repository_RepositoryAction_0: n/a
16:BeeModel.buildUnits[0]->BuildUnit'aTestUnit'.repositories[0]->Repository'TestRepo': "cvs TestRepo { user = "hello" ; password = "hush-hu...":
  -> Repository_DocumentationAssignment_1: Repository.documentation is not set.
  -> Repository_RepositoryAction_0: n/a
11:BeeModel.buildUnits[0]->BuildUnit'aTestUnit'.repositories[0]->Repository'TestRepo': "cvs TestRepo { password = "hush-hush" ; }":
  -> Repository_DocumentationAssignment_1: Repository.documentation is not set.
  -> Repository_RepositoryAction_0: n/a
6:BeeModel.buildUnits[0]->BuildUnit'aTestUnit'.repositories[0]->Repository'TestRepo': "; }":
  -> Repository_BranchesAssignment_5_4_2_1: All 0 values of Repository.branches have been consumed. More are needed to continue here.
5:BeeModel.buildUnits[0]->BuildUnit'aTestUnit'.repositories[0]->Repository'TestRepo': "} }":
  -> Repository_OptionsAssignment_5_5_2: All 0 values of Repository.options have been consumed. More are needed to continue here.
    at org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:50)
    at org.eclipse.xtext.ui.editor.quickfix.QuickAssistCompletionProposal.apply(QuickAssistCompletionProposal.java:32)
    at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:933)
    at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:879)
    at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$27(CompletionProposalPopup.java:875)
    at org.eclipse.jface.text.contentassist.CompletionProposalPopup$5.widgetDefaultSelected(CompletionProposalPopup.java:657)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:113)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3706)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1314)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1337)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1322)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1136)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3566)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3224)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2407)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2371)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2220)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:367)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:611)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:566)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1363)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1339)

If there is DOCUMENTATION it works
---
I.e. if I insert a documentation comment like
/** this is documentation */
the serialization, and the quick fix works.

If there is documentation, but it is converted to an empty string by my terminal converted (which trims strings). i.e. input like
/**
*/
I also get serialization errors.
Comment 1 Sebastian Zarnekow CLA 2010-05-10 14:28:08 EDT
I simplified the grammar to look like this:

Model : 
	  (documentation = STRING)?
	  handlerType = ID
	  name = ID
	  '{'
	      (
	        ("remote" '=' remote = ID ';')?
	      & ("local" '=' local = ID ';')?
	      & ("user" '=' user = STRING ';')?
	      & ("password" '=' password = STRING ';')?
	      & ("branches" branches += ID (',' branches += ID)* ';')?
	      & ("options" '{' (options += ID)+ '}' )?
	      )
	  '}'
;

The test is green. I'll have a closer look at the actual value converters.
Comment 2 Sebastian Zarnekow CLA 2010-05-10 14:43:11 EDT
Serialization result is 

cvs TestRepo { remote = "http://abc.org" ; local = "file://aLocalURL/" ; user = "hello" ; password = "hush-hush" ; }

which looks pretty much as I've expected.
Comment 3 Sebastian Zarnekow CLA 2010-05-11 09:39:36 EDT
Worksforme. The original exception was caused by a bug in the transient value service.
Comment 4 Karsten Thoms CLA 2017-09-19 16:37:59 EDT
Closing bug which were set to RESOLVED before Eclipse Neon.0.