This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 475934 - Model processing order in the ModelAssembler
Summary: Model processing order in the ModelAssembler
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: 4.6 M7   Edit
Assignee: Jonas Helming CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 480610
Blocks:
  Show dependency tree
 
Reported: 2015-08-26 10:36 EDT by Alexandra Buzila CLA
Modified: 2016-04-28 10:51 EDT (History)
7 users (show)

See Also:
Lars.Vogel: pmc_approved+


Attachments
example e4 app with processor (9.04 KB, application/x-zip-compressed)
2015-08-26 10:36 EDT, Alexandra Buzila CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandra Buzila CLA 2015-08-26 10:36:11 EDT
Created attachment 256135 [details]
example e4 app with processor

Currently, the ModelAssembler#processModel(boolean) method processes the model elements in this order:
- processors marked to run before fragments are executed
- fragments are processed
- processors marked to run after fragments are executed
- imports are resolved

Because the imports are resolved last, a ClassCastException is thrown when trying to get the container of the model elements from a processor:

Caused by: java.lang.ClassCastException: org.eclipse.e4.ui.model.fragment.impl.ModelFragmentsImpl cannot be cast to org.eclipse.e4.ui.model.application.ui.MUIElement
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.getContainer(ModelServiceImpl.java:850)
	at TestModelProcessingOrder.ExampleProcessor.execute(ExampleProcessor.java:18)

I'm attaching an example e4 app with a processor that can be used to reproduce the problem.

Is there a particular reason why the imports are resolved last?
Comment 1 Brian de Alwis CLA 2015-08-27 10:33:09 EDT
So there's a bug in that getContainer() shouldn't CCE since we should be able to have arbitrary containers.

It does seem strange that the post-fragment processors operate on a semi-complete model.  Change the ordering seems legit, and indeed it's what I assumed how the operations were ordered.  The impact is that a post-fragment processor cannot alter the elements loaded from a fragment.  But I'm not sure a fragment is appropriate in that situation.
Comment 2 Jonas Helming CLA 2015-08-28 10:27:16 EDT
We will provide a fix for this one, actually both, the order issue and the CCE
Comment 3 Eclipse Genie CLA 2016-02-25 09:53:29 EST
New Gerrit change created: https://git.eclipse.org/r/67335
Comment 4 Alexandra Buzila CLA 2016-02-25 09:55:57 EST
I pushed the fix  for the model processing order, based on the refactored version of the ModelAssembler.
Comment 5 Alexandra Buzila CLA 2016-02-25 10:59:50 EST
I opened bug 488478 for the problem with the getContainer method of the model service.
Comment 6 Brian de Alwis CLA 2016-04-04 10:11:44 EDT
Jonas, technically this is a change in API (since order of processing is changed) and requires PMC approval before being committed.
Comment 7 Mike Wilson CLA 2016-04-05 13:04:47 EDT
Re "Jonas, technically this is a change in API (since order of processing is changed)" --
Is the processing order actually specified in the API, or are we just worrying about the possibility of there being existing code that relied on the old order?

If it's the latter, then I'd like to understand what we've done to communicate the change to the community and get feedback on impact.
Comment 8 Jonas Helming CLA 2016-04-06 04:57:34 EDT
I am not aware that the current order is communicated somehow. IMHO, the current order does not make sense at all.
Actually, it is more the opposite case: The API allows that processors can be executed AFTER fragments, In fact, without the fix, those processors are executed somewhere in the middle of the fragment merging, before their imports get resolved.
About existing users: It is hard for me to envision a real use case, where somebodies code would not work after this fix. It would be:

- Element A is in a fragment to be merged
- Element B is reference by A and is in the core model or another fragment and therefore an import in the fragment of A

Now you need an after-fragment-processor, which accesses A after merging, retrieves B from it and then assume, that A is still the import proxy, but not yet the resolved real element.

Another theoretical use case would be to programatically add imports to the fragment after it has been merged. But it would be hard to access the fragment at that point in time.

To sum up: It is hard to imagine, that someone relies on the current order. Of course, you never know. I therefore would suggest to add this to the N&N?
Comment 9 Jonas Helming CLA 2016-04-06 04:58:23 EDT
One more comment: Personally, I would not consider this to be an API change, although you could argue on that...
Comment 10 Mike Wilson CLA 2016-04-06 12:24:20 EDT
I agree that if we haven't communicated the order, then it's not an API change. I also agree that the current order seems broken.

My worry was just whether we've given our consumers enough time to react to the change, if we believed that there is working code out there that could depend on the current behaviour. It sounds like the answer to that is no.
Comment 11 Brian de Alwis CLA 2016-04-06 12:41:51 EDT
I missed that the ModelAssembler is an internal class.  That said, the order is in the javadoc, it has been there for several releases, and it's a behavioural change.  But the actual behaviour is weird and requires the developer to write special-case code to handle the weird intermediate state.

I think posting to e4-dev and the Eclipse 4 Forum pointing to this bug would be sufficient.
Comment 12 Jonas Helming CLA 2016-04-07 04:00:48 EDT
So do we agree that this does not require PMC approval? In this case, I would accept the fix, and create the posts Brian mentioned.
Comment 13 Lars Vogel CLA 2016-04-08 14:38:34 EDT
The old order does not make sense, +1 for changing that. I think we need to discuss that in the next PMC call.
Comment 14 Dani Megert CLA 2016-04-09 03:34:21 EDT
(In reply to Lars Vogel from comment #13)
> The old order does not make sense, +1 for changing that. I think we need to
> discuss that in the next PMC call.

I'll put it in the agenda for Tuesday.
Comment 15 Lars Vogel CLA 2016-04-12 13:25:02 EDT
This change has been approved by the PMC. See https://wiki.eclipse.org/Eclipse/PMC

Jonas, you can commit the change.
Comment 16 Lars Vogel CLA 2016-04-12 13:37:06 EDT
(In reply to Lars Vogel from comment #15)
> Jonas, you can commit the change.

Please ensure you announce it widely. I would guess that posting to cross is not necessary. I leave that to Dani to correct, if that is also required.  I suggest that you follow Brians suggestion:
---
I think posting to e4-dev and the Eclipse 4 Forum pointing to this bug would be sufficient.
---
Comment 17 Lars Vogel CLA 2016-04-25 15:11:24 EDT
Mass move to 4.6 RC1. We might push out more to 4.7.
Comment 19 Alexandra Buzila CLA 2016-04-28 10:51:02 EDT
Verified in I20160427-2000