Bug 527110 - Issue with serialisation code in Generic Editor
Summary: Issue with serialisation code in Generic Editor
Status: CLOSED FIXED
Alias: None
Product: ECP
Classification: Modeling
Component: EMF Forms (show other bugs)
Version: 1.14.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 1.19.0   Edit
Assignee: Alexandra Buzila CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy, test
Depends on:
Blocks:
 
Reported: 2017-11-10 06:00 EST by Hallvard Traetteberg CLA
Modified: 2018-11-16 06:15 EST (History)
2 users (show)

See Also:


Attachments
Project that demonstrates the bug (49.00 KB, application/octet-stream)
2018-03-10 12:17 EST, Hallvard Traetteberg CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hallvard Traetteberg CLA 2017-11-10 06:00:34 EST
The GenericEditor serializes certain models slightly differently than the Sample Reflective Ecore editor. The differences occurs with models containing EClasses with Extended meta data to support XML serialization, when these are included in XMIResources. In this case, the serialization shouldn't use the Extended meta data, but it does, so you may end up with XML that cannot be read as proper XMI for the model. See https://www.eclipse.org/forums/index.php/t/1089914/ for details of the case.

The problem is that the GenericEditor sets the load option XMLResource.OPTION_RECORD_UNKNOWN_FEATURE to Boolean.TRUE before loading, and that this in turn (somehow) sets the EXTENDED_META_DATA option in the Resource's defaultSaveOptions, which instructs the save method to serialise as XML, rather than XMI). If I clear the load options in the debugger, before the initial load, the EXTENDED_META_DATA options is not set, and the serialization is proper XMI.

I suggest that GenericEditor does not set the XMLResource.OPTION_RECORD_UNKNOWN_FEATURE option to TRUE, so this side-effect is avoided.
Comment 1 Eugen Neufeld CLA 2017-11-10 06:07:47 EST
Thank you for the report.

We will discuss this and post updates here.
Comment 2 Alexandra Buzila CLA 2018-03-05 08:06:22 EST
Hallvard, could you please provide a small example to reproduce the issue? Thank you!
Comment 3 Hallvard Traetteberg CLA 2018-03-10 12:17:04 EST
Created attachment 273078 [details]
Project that demonstrates the bug

This is a minimal project demonstrating the bug. It contains two models, one using XML annotions that changes how models are serialized, the other depending on the first, but using XMI serialization. Two examples instances are provided, one (model/Path.xmi) extension) that can be read by the Sample Reflective Ecore Editor, but not by ECF's Generic Editor (it can be read, but some attributes are ignored), and another (model/Path.bug527110b) that can be read by the Generic Editor (is in fact, written by it), but not by the Sample Reflective Ecore Editor. The project declares the Generic Editor as the editor for the bug527110b extension, so it a runtime Eclipse can be launched and used to open Path.bug527110b with either editor.
Comment 4 Eclipse Genie CLA 2018-06-05 10:23:31 EDT
New Gerrit change created: https://git.eclipse.org/r/124027
Comment 5 Hallvard Traetteberg CLA 2018-06-05 11:49:00 EDT
The fix seems to force all Resources to be save with XMLResource.OPTION_EXTENDED_META_DATA set to false. But won't this break Resources that should be serialized as XML? Resources that (already) are (supposed to be) stored as XML should be loaded and saved as XML. It's the (default) Resource implementation (the one registered for the file extension in the global or ResourceSet registry) that should decide, not the editor.

The test needs to check that both cases work properly, when the resource is an XMLResource it should be serialized as XML, when the resource is an XMIResource, it should be serialized as XMI.
Comment 6 Alexandra Buzila CLA 2018-08-22 09:02:14 EDT
Hallvard, could you please test the Gerrit change and see if this fixes your issue?
Comment 7 Eugen Neufeld CLA 2018-09-03 11:31:35 EDT
I have to move it as we have to release next week.
We will merge it after a thorough test after the current release.
Comment 9 Alexandra Buzila CLA 2018-11-16 06:14:38 EST
We deprecated the save/load methods of ResourceSetHelpers that did not accept resource load/save options and introduce new methods to replace them, that expect these as a parameter. Clients are now responsible for passing
in the expected options and the helper class should not specify any.

This affects the GenericEditor and its subclasses. The GenericEditor also throws a new PartInitException, if there were errors while loading the resource.