Bug 514982 - Diagram Editor destroys unknown files
Summary: Diagram Editor destroys unknown files
Status: CLOSED FIXED
Alias: None
Product: Sirius
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows NT
: P3 major (vote)
Target Milestone: 5.1.0   Edit
Assignee: Jessy Mallet CLA
QA Contact: Julien Dupont CLA
URL:
Whiteboard: backport
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2017-04-09 07:19 EDT by Peter Feichtinger CLA
Modified: 2017-11-08 03:36 EST (History)
4 users (show)

See Also:


Attachments
Log entry of the exception thrown when trying to open an unknown file (8.30 KB, text/plain)
2017-04-09 07:19 EDT, Peter Feichtinger CLA
no flags Details
The resulting file after attempting to open with Sirius diagram editor (171 bytes, application/xml)
2017-04-09 07:20 EDT, Peter Feichtinger CLA
no flags Details
Ecore file that gets corrupted (237 bytes, application/octet-stream)
2017-04-10 15:01 EDT, Peter Feichtinger CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Feichtinger CLA 2017-04-09 07:19:35 EDT
Created attachment 267711 [details]
Log entry of the exception thrown when trying to open an unknown file

When opening an unknown file with the Sirius diagram editor, it fails to open, which is to be expected, but it also overwrites the contents of the opened file, which most certainly should not happen.
It doesn't matter what kind of file is opened (I tried different text files).

This is with Sirius version 4.1.3 on Neon.3. Attached is an exception that is logged when trying to open an Ecore model (I know this is not supposed to work, just for demonstration), as well as the changed file after the editor failed to open.

Please ask if you need any more information.
Comment 1 Peter Feichtinger CLA 2017-04-09 07:20:40 EDT
Created attachment 267712 [details]
The resulting file after attempting to open with Sirius diagram editor
Comment 2 Steve Monnier CLA 2017-04-10 11:31:34 EDT
Hello,

Is it possible to have a sample to reproduce this issue? 
With a modeling project containing an ecore model and a .txt file, i tried to open both files and the .aird with the Sirius Diagram Editor and only had a Null Pointer Exception in org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor$1.run(DiagramDocumentEditor.java:130). The file themselves remained untouched and I could still open them with their matching editor afterward.

Regards,
Steve
Comment 3 Steve Monnier CLA 2017-04-10 11:32:10 EDT
I tried to reproduce with Sirius 4.1.3 and with the master branch.
Comment 4 Peter Feichtinger CLA 2017-04-10 15:00:53 EDT
So I tried again with a text file and even an XML file, and I also got the NPE you mentioned.
It only seems so "work" when Eclipse knows the file will contain XML content or something like that. I got it to work by copying an Ecore model into the project or creating a new one. It works whether the project has the modeling nature or not.
I'll attach the test file.
Comment 5 Peter Feichtinger CLA 2017-04-10 15:01:35 EDT
Created attachment 267739 [details]
Ecore file that gets corrupted
Comment 6 Peter Feichtinger CLA 2017-04-10 15:08:55 EDT
In case you still can't reproduce it, the original case where I first encountered this was in an example project from Epsilon. In the example titled "Implement a GMF editor with image nodes using EuGENia" there is a file `model/friends.ecorediag` that when opened gets corrupted.
Comment 7 Maxime Porhel CLA 2017-04-18 09:22:10 EDT
Hi Peter, 

I tried with Eclipse Modeling (Neon.3, macOS) + Epsilon 1.2 installed from the MarketPlace. I get the same log than you and I also have a corruption. The "Sirius Diagram Editing" editor is not proposed by Eclipse, users has to go in "open with > other" and look for it.

Note that the Sirius Diagram Editor is not intended to be used to open files (except .aird files in some cases). Bug 510040 will soon bring a proper Eclipse editor for .aird files with direct access to session operations.

Regards
Comment 8 Peter Feichtinger CLA 2017-04-18 09:38:53 EDT
I do realize that it's not meant to open files directly, nonetheless it shouldn't overwrite files without warning when used this way.
I only tried it because I couldn't find an editor for the .ecorediag file (I still haven't found one BTW).
Comment 9 Pierre-Charles David CLA 2017-04-18 09:50:39 EDT
(In reply to Peter Feichtinger from comment #8)
> I do realize that it's not meant to open files directly, nonetheless it
> shouldn't overwrite files without warning when used this way.
> I only tried it because I couldn't find an editor for the .ecorediag file (I
> still haven't found one BTW).

".ecorediag" are legacy diagrams created with old versions of Ecore Tools 1.x, before Ecore Tools was rewritten based on Sirius (starting from 2.0).

To open them you'll need to install an old version of Ecore Tools (which does not use Sirius at all). I think the last was 1.2, which seems still available at http://download.eclipse.org/ecoretools/updates/1.2/ (but not maintained).
Comment 10 Maxime Porhel CLA 2017-04-18 10:09:10 EDT
On master I have the same NPE than Steve but no file corruption.
Comment 11 Eclipse Genie CLA 2017-04-18 11:22:37 EDT
New Gerrit change created: https://git.eclipse.org/r/95196
Comment 12 Maxime Porhel CLA 2017-04-18 11:27:32 EDT
Peter, thank you for your detailed bug report. 

We have reproduced this issue and we reckon it is valid. 
Nevertheless it's not yet in the scope of a release, I'm marking it so that we also consider it for inclusion for a future maintenance release.
Comment 13 Maxime Porhel CLA 2017-04-18 11:29:20 EDT
(In reply to Maxime Porhel from comment #10)
> On master I have the same NPE than Steve but no file corruption.

On master but without any addtional SessionFactory, I have the ClassCastException and the file corruption. 
Tester must check that the SessionFactory.INSTANCE is org.eclipse.sirius.business.internal.session.SessionFactoryImpl
Comment 14 Eclipse Genie CLA 2017-08-02 13:08:39 EDT
New Gerrit change created: https://git.eclipse.org/r/102407
Comment 16 Pierre-Charles David CLA 2017-08-22 04:30:38 EDT
I think were're done here. For validation purposes, here are explicit reproduction steps:
1. Create a plain project in the workspace, and copy the attached test.ecore inside.
2. Right-click on the ecore, select Open With... > Other... and then choose "Sirius Diagram Editing". Close the dialog with "OK".
3. An error editor appears, which is not ideal in terms of user feedback, but acceptable for now. Close the editor.
4. Right-click on the ecore again, and now select Open With > Text Editor.

Before the fix, the ecore was replaced by an empty DAnalysis, completely overwriting the original semantic model in the file (KO). With the fix in ab7bcb88e97bab8abd1eaf8c758aa86b93275dbf, we still have the error opening the editor, but the semantic model has not been touched (OK).
Comment 17 Pierre-Charles David CLA 2017-11-08 03:36:56 EST
Available in Sirius 5.1.0, see https://wiki.eclipse.org/Sirius/5.1.0.