When attempting to generate XML Mapping files for some java classes, the wizard is failing after the second step. When looking at the error log, I'm seeing the following stack trace:
java.lang.ClassCastException: class org.eclipse.jdt.core.dom.EnumDeclaration cannot be cast to class org.eclipse.jdt.core.dom.TypeDeclaration (org.eclipse.jdt.core.dom.EnumDeclaration and org.eclipse.jdt.core.dom.TypeDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @65432d8a)
at org.hibernate.eclipse.jdt.ui.wizards.ProcessEntityInfo.varHasGetterAndSetter(ConfigurationActor.java:417)
at org.hibernate.eclipse.jdt.ui.wizards.ProcessEntityInfo.visit(ConfigurationActor.java:392)
at org.eclipse.jdt.core.dom.FieldDeclaration.accept0(FieldDeclaration.java:265)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2998)
at org.eclipse.jdt.core.dom.EnumDeclaration.accept0(EnumDeclaration.java:261)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2998)
at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:447)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2998)
at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:261)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
at org.hibernate.eclipse.jdt.ui.wizards.ConfigurationActor.createConfiguration(ConfigurationActor.java:160)
at org.hibernate.eclipse.jdt.ui.wizards.ConfigurationActor.createConfigurations(ConfigurationActor.java:114)
at org.hibernate.eclipse.jdt.ui.wizards.NewHibernateMappingFileWizard.createConfigurations(NewHibernateMappingFileWizard.java:543)
at org.hibernate.eclipse.jdt.ui.wizards.NewHibernateMappingFileWizard.getPlaces2Gen(NewHibernateMappingFileWizard.java:308)
at org.hibernate.eclipse.jdt.ui.wizards.NewHibernateMappingFileWizard.handlePageChanging(NewHibernateMappingFileWizard.java:169)
at org.eclipse.jface.wizard.WizardDialog$6.run(WizardDialog.java:1566)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.ui.internal.JFaceUtil.lambda$0(JFaceUtil.java:47)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174)
at org.eclipse.jface.wizard.WizardDialog.firePageChanging(WizardDialog.java:1563)
at org.eclipse.jface.wizard.WizardDialog.doPageChanging(WizardDialog.java:931)
at org.eclipse.jface.wizard.WizardDialog.showPage(WizardDialog.java:1215)
at org.eclipse.jface.wizard.WizardDialog.nextPressed(WizardDialog.java:918)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:468)
at org.eclipse.jface.dialogs.Dialog.lambda$0(Dialog.java:619)
at org.eclipse.swt.events.SelectionListener$1.widgetSelected(SelectionListener.java:84)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:252)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5676)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1423)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4935)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4429)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:823)
at org.eclipse.jface.window.Window.open(Window.java:799)
at org.eclipse.ui.internal.actions.NewWizardShortcutAction.run(NewWizardShortcutAction.java:130)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:474)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:579)
at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:413)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5676)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1423)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4935)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4429)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1160)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1049)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:660)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:559)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:154)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
I went through my code and tracked down the individual class that was causing the failure. The problem comes from a static enum with a constructor and private field (see the attached file). Something about the presence of a variable nested inside an enum is causing the hibernate mapping generation to fail. Steps to reproduce:
- Create a java class containing a static enum with a field and constructor.
- Right click on the class and select 'New' -> 'Hibernate XML Mapping file'
- Select the target class and click 'Next'
- Confirm the class name and file name and click 'Next' again
Results: An error dialog will display with the message: "class org.eclipse.jdt.core.dom.EnumDeclaration cannot be cast to class org.eclipse.jdt.core.dom.TypeDeclaration" |