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

Bug 438425

Summary: "service:" is broken right after "extract to aird file..."
Product: [Modeling] Sirius Reporter: Stéphane Thibaudeau <stephane.thibaudeau>
Component: CoreAssignee: Pierre-Charles David <pierre-charles.david>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: florian.barbin, maxime.porhel, pierre-charles.david
Version: 1.0.0Keywords: triaged
Target Milestone: 1.0.1   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 439615    
Attachments:
Description Flags
Exampe VSM
none
Test project none

Description Stéphane Thibaudeau CLA 2014-06-27 13:03:17 EDT
Created attachment 244614 [details]
Exampe VSM

Right after extracting a diagram in a new aird file, java services can not be called anymore.

Steps to reproduce :
1 - import VSM project
2 - launch new runtime
3 - import test project in runtime
4 - open or create diagram on "first" EPackage => each EClass is displayed twice. One mapping uses "service:getEClasses()", the other one uses "[getEClasses()/]" to call a Java service.
5 - save
6 - In model explorer view, right click on diagram and choose "extract to aird file...". Create a new aird file in the same project.
7 - navigate to open the diagram which is now located in the other aird file.
=> Error log has messages explaining the service "getEClasses()" could not be found. The corresponding mappings are not created anymore.
8 - close and open project. The diagram is now OK.

After a bit of debugging I've found out that in ODesignGenericInterpreter.getInterpreter(), a ServiceInterpreter is retrieved. But the "services" map on this ServiceInterpreter is empty.
If this interpreter was null it would be properly created.
Comment 1 Stéphane Thibaudeau CLA 2014-06-27 13:03:47 EDT
Created attachment 244615 [details]
Test project
Comment 2 Stéphane Thibaudeau CLA 2014-06-30 05:40:53 EDT
When a diagram is extracted to another aird :

1) a new View is created in the new aird file
2) when the view is created DAnlysisSessionImpl.initInterpreter() is called
3) setProperty(IInterpreter.FILES, null) is called on ODesignGenericInterpreter
4) setProperty(IInterpreter.FILES, null) is called on loaded interpreters, it is so called on ServiceInterpreter
5) In ServiceInterpreter.setProperty() when passed "files" and null as parameters the "services" map is not modified
6) Then in DAnlysisSessionImpl.initInterpreter(), setProperty(IInterpreter.FILES, List of odesign files) is called on ODesignGenericInterpreter
7) In ServiceInterpreter, when setPropertty() is called with "files" and a List as  arguments the "services" map is cleared.

Next time, Sirius will need the ServiceInterpreter it will get a non-null interpreter but with a empty "services" map. So there is no available service.
Comment 3 Florian Barbin CLA 2014-07-01 04:02:27 EDT
We should not "reinitialize" existing interpreters when creating a new view.
Comment 4 Pierre-Charles David CLA 2014-07-07 07:05:03 EDT
(In reply to Florian Barbin from comment #3)
> We should not "reinitialize" existing interpreters when creating a new view.

I'm not so sure. This was probably done for a good reason, and is expected of all the other interpreter implementations. If only service: is broken, the fix has a good chance of being in its implementation, not in changing code that can affect all other interpters, at the risk of subtly breaking them.

From a quick look at the code, in org.eclipse.sirius.common.tools.internal.interpreter.ServiceInterpreter.setProperty(Object, Object), after services.clear(), it may be enough to do something like this:

for (String import : Lists.newArrayList(imports)) {
  addImport(import);
}

To force the re-discovery of the services based on the new "bundle-path" implied by the new value of the FILES property.

Note that (from Stéphane's comment) "In ServiceInterpreter.setProperty() when passed "files" and null as parameters the "services" map is not modified": this is probably a bug. In this specific scenario we do not care because DASI.initInterpreter() call setProperty() with a non-null value right after, but it is still a bug.
Comment 5 Pierre-Charles David CLA 2014-07-10 08:42:41 EDT
See https://git.eclipse.org/r/#/c/29734/
Comment 6 Maxime Porhel CLA 2014-07-15 09:11:07 EDT
Corrected on branch 1.0.x by commit 430d7db20ac54c62d2c021d691960dce378ad387
Comment 7 Pierre-Charles David CLA 2015-05-20 07:55:46 EDT
Available in Sirius 1.0.1.