eclipse.platform.ui icon indicating copy to clipboard operation
eclipse.platform.ui copied to clipboard

ClassCastException in EcoreEList.set when using notexists in fragment

Open grozadanut opened this issue 1 year ago • 1 comments

java.lang.ClassCastException: class org.eclipse.e4.ui.model.application.commands.impl.BindingContextImpl cannot be cast to class java.util.List (org.eclipse.e4.ui.model.application.commands.impl.BindingContextImpl is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @487cb74a; java.util.List is in module java.base of loader 'bootstrap')
	at org.eclipse.emf.ecore.util.EcoreEList.set(EcoreEList.java:457)
	at org.eclipse.e4.ui.model.internal.ModelUtils.mergeList(ModelUtils.java:190)
	at org.eclipse.e4.ui.model.internal.ModelUtils.merge(ModelUtils.java:152)
	at org.eclipse.e4.ui.model.fragment.impl.StringModelFragmentImpl.mergeIdList(StringModelFragmentImpl.java:345)
	at org.eclipse.e4.ui.model.fragment.impl.StringModelFragmentImpl.merge(StringModelFragmentImpl.java:323)
	at ro.linic.ui.base.eclipse.fixes.ModelAssembler.processModelFragment(ModelAssembler.java:640)
	at ro.linic.ui.base.eclipse.fixes.ModelAssembler.processFragment(ModelAssembler.java:529)
	at ro.linic.ui.base.eclipse.fixes.ModelAssembler.processFragments(ModelAssembler.java:489)
	at ro.linic.ui.base.eclipse.fixes.ModelAssembler.processFragmentWrappers(ModelAssembler.java:459)
	at ro.linic.ui.base.eclipse.fixes.ModelAssembler.processFragments(ModelAssembler.java:386)
	at ro.linic.ui.base.eclipse.fixes.ModelAssembler.processModel(ModelAssembler.java:331)
	at ro.linic.ui.base.eclipse.fixes.ResourceHandler.loadMostRecentModel(ResourceHandler.java:187)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.loadApplicationModel(E4Application.java:371)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:247)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:155)

I get the exception above when using notexists flag for a fragment. The problem seems to be in EcoreEList.set where the parameter is cast to a list, but in ModelUtils.mergeList we can see that the element is an instance of MApplicationElement, not a list. In ModelUtils.mergeList line 190 the setting is an instance of EObjectResolvingEList.

Note: ro.linic.ui.base.eclipse.fixes.ModelAssembler is just a copy of org.eclipse.e4.ui.internal.workbench.ModelAssembler.

Note: Applying the fix from https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/144622/4/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelAssembler.java meaning removing the existing elements from the fragment before merging seems to fix this exception.

grozadanut avatar Feb 27 '24 13:02 grozadanut

I suspect no one will try to fix this for you. It's pretty easy to set up an IDE with the sources such that you can create a pull request:

https://github.com/eclipse-platform/.github/blob/main/CONTRIBUTING.md#creating-an-eclipse-development-environment

It's problematic that you don't provide a test case nor even a way for someone else to reproduce the problem. 😞

merks avatar Feb 28 '24 15:02 merks