Skip to content

Skip type-incompatible imports in ModelAssembler.resolveImports#4150

Draft
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:lv/modelassembler-import-type-regression-test
Draft

Skip type-incompatible imports in ModelAssembler.resolveImports#4150
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:lv/modelassembler-import-type-regression-test

Conversation

@vogella

@vogella vogella commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

ModelAssembler.resolveImports resolves fragment <imports> by elementId only, ignoring the element type, then sets whatever it finds on the target reference. When a fragment imports an element whose id collides with a different-typed element already in the model, the resolved element is not assignable to the reference and model assembly aborts with a ClassCastException. This is what breaks ResourceHandlerTest in the I-builds (BindingTableImpl cannot be cast to MBindingContext).

The import is now skipped with a warning instead of aborting the whole application model: an import that resolves to an incompatible element is a contribution error, so the reference is left unset and every other fragment still applies. Unresolved imports on many-valued features are skipped rather than throwing an NPE. A regression test in ModelAssemblerTests covers the type mismatch.

Fixes #4148

@vogella

vogella commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

The new test is supposed to fail, this is to demo the problem.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Test Results

   855 files  ±0     855 suites  ±0   53m 18s ⏱️ -6s
 8 096 tests +1   7 853 ✅ +1  243 💤 ±0  0 ❌ ±0 
20 190 runs  +3  19 536 ✅ +3  654 💤 ±0  0 ❌ ±0 

Results for commit 7cba137. ± Comparison against base commit 0aaee1a.

♻️ This comment has been updated with latest results.

resolveImports resolves fragment <imports> by elementId via
ModelUtils.findElementById, which returns the first match regardless of
type, and then eSets it onto the target reference. When the model
contains a different-typed element sharing the imported id, the eSet
fails with a ClassCastException and aborts assembly of the whole
application model. For example ResourceHandlerTest fails in the I-builds
with "BindingTableImpl cannot be cast to MBindingContext", because
BindingToModelProcessor.createTable() gives each generated BindingTable
the binding-context id as its own elementId, so a fragment importing that
BindingContext resolves to the same-id BindingTable.

Skip such an import with a warning instead: an import that resolves to an
incompatible element is a contribution error, not a reason to abort
assembly. The reference is left unset and every other fragment still
applies. Also skip, rather than NPE, an unresolved import on a
many-valued feature. Add a regression test covering the type mismatch.

Fixes eclipse-platform#4148
@vogella vogella force-pushed the lv/modelassembler-import-type-regression-test branch from 0236660 to 7cba137 Compare July 2, 2026 17:12
@vogella vogella changed the title Add regression test reproducing ClassCastException for type-incompatible fragment import Skip type-incompatible imports in ModelAssembler.resolveImports Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResourceHandlerTest fails in I-build

1 participant