Fix ClassCastException when creating new class from Direct Menu Item#1993
Closed
Fix ClassCastException when creating new class from Direct Menu Item#1993
Conversation
Copilot
AI
changed the title
[WIP] Fix ClassCastException when creating new class from menu
Fix ClassCastException when creating new class from Direct Menu Item
Oct 7, 2025
29e0801 to
865fc4f
Compare
Creating a new class via the "Class URI" link in the E4 application model editor threw a ClassCastException due to an invalid type conversion in the data binding configuration of AbstractNewClassPage.java. The target-to-model UpdateValueStrategy was missing a converter to transform the String value from the text field into an IPackageFragmentRoot, leading to a failed cast by the default converter. This change introduces StringToPackageFragmentRootConverter to properly map String paths to IPackageFragmentRoot instances and integrates it into the data binding setup. Users can now open the new class wizard and create handler classes without errors.
865fc4f to
f4a3bee
Compare
Test Results 471 files - 281 471 suites - 281 47m 58s ⏱️ - 1m 5s For more details on these failures and errors, see this check. Results for commit f4a3bee. ± Comparison against base commit b584f1d. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When clicking on the "Class URI" link for a Direct Menu Item in the E4 application model editor to create a new class, a
ClassCastExceptionwas thrown:This prevented users from creating new handler classes through the application model editor UI.
Root Cause
The issue was in the data binding configuration for the "Source Folder" text field in
AbstractNewClassPage.java. The target-to-modelUpdateValueStrategywas missing a converter to properly transform theStringvalue from the Text widget into anIPackageFragmentRootobject. When the databinding framework attempted to perform this conversion, it fell back to the default converter which attempted a direct cast, resulting in the exception.Solution
This PR adds a new
StringToPackageFragmentRootConverterclass that properly converts String paths toIPackageFragmentRootobjects by:IPackageFragmentRootornullif not foundThe converter is now used in the target-to-model
UpdateValueStrategy, ensuring proper type conversion instead of attempting a direct cast.Changes
StringToPackageFragmentRootConverterclass extendingConverter<String, IPackageFragmentRoot>.setConverter(new StringToPackageFragmentRootConverter(fWorkspaceRoot))The implementation follows the existing pattern used by similar converters in the same class (
StringToPackageFragmentConverter,PackageFragmentRootToStringConverter) and properly handles edge cases like null/empty strings and conversion failures.Testing
After this fix, users should be able to:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
repo.eclipse.org/usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/eclipse.pde/eclipse.pde org.codehaus.plexus.classworlds.launcher.Launcher clean compile(dns block)/usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/eclipse.pde/eclipse.pde org.codehaus.plexus.classworlds.launcher.Launcher clean compile -pl e4tools/bundles/org.eclipse.e4.tools -am(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>java.lang.ClassCastException: Cannot cast java.lang.String to org.eclipse.jdt.core.IPackageFragmentRoot</issue_title>
<issue_description>If I click on the Class URI link for a Direct Menu item in the application model to create a new class I receive the following exception.
java.lang.ClassCastException: Cannot cast java.lang.String to org.eclipse.jdt.core.IPackageFragmentRoot
at java.base/java.lang.Class.cast(Class.java:4067)
at org.eclipse.core.databinding.UpdateStrategy$DefaultConverter.convert(UpdateStrategy.java:682)
at org.eclipse.core.databinding.UpdateStrategy.convert(UpdateStrategy.java:655)
at org.eclipse.core.databinding.UpdateValueStrategy.convert(UpdateValueStrategy.java:1)
at org.eclipse.core.databinding.ValueBinding.lambda$0(ValueBinding.java:177)
at org.eclipse.core.databinding.Binding.lambda$3(Binding.java:193)
at org.eclipse.core.databinding.observable.Realm$1.run(Realm.java:155)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:159)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:177)
at org.eclipse.core.databinding.Binding.execAfterDisposalCheck(Binding.java:191)
at org.eclipse.core.databinding.ValueBinding.doUpdate(ValueBinding.java:163)
at org.eclipse.core.databinding.ValueBinding.validateTargetToModel(ValueBinding.java:240)
at org.eclipse.core.databinding.ValueBinding.postInit(ValueBinding.java:104)
at org.eclipse.core.databinding.Binding.init(Binding.java:82)
at org.eclipse.core.databinding.DataBindingContext.bindValue(DataBindingContext.java:201)
at org.eclipse.e4.internal.tools.wizards.classes.AbstractNewClassPage.createControl(AbstractNewClassPage.java:252)
at org.eclipse.jface.wizard.Wizard.createPageControls(Wizard.java:179)
at org.eclipse.jface.wizard.WizardDialog.createPageControls(WizardDialog.java:744)
at org.eclipse.jface.wizard.WizardDialog.createContents(WizardDialog.java:637)
at org.eclipse.jface.window.Window.create(Window.java:431)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1088)
at org.eclipse.jface.window.Window.open(Window.java:788)
at org.eclipse.e4.tools.emf.editor3x.extension.HandlerContributionEditor.createOpen(HandlerContributionEditor.java:60)
at org.eclipse.e4.tools.emf.editor3x.extension.HandlerContributionEditor.createOpen(HandlerContributionEditor.java:122)
at org.eclipse.e4.tools.emf.editor3x.extension.HandlerContributionEditor.createOpen(HandlerContributionEditor.java:49)
at org.eclipse.e4.tools.emf.ui.internal.common.component.ControlFactory$12.widgetSelected(ControlFactory.java:859)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:286)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5884)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1656)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1682)
at org.eclipse.swt.widgets.Widget.sendSelectionEvent(Widget.java:1832)
at org.eclipse.swt.widgets.Link.gtk_button_release_event(Link.java:426)
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:2624)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:6868)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:6191)
at org.eclipse.swt.internal.gtk3.GTK3.gtk_main_do_event(Native Method)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1619)
at org.eclipse.swt.internal.gtk3.GTK3.gtk_main_iteration_do(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4537)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1147)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1038)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:677)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:583)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:185)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:219)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:149)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:115)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:467)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(E...
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.