eclipse-pde / eclipse.pde

Eclipse Public License 2.0
24 stars 58 forks source link

class org.eclipse.jdt.internal.core.JavaNature cannot be cast to class org.eclipse.jdt.core.IJavaProject #1215

Closed gregh3269 closed 3 months ago

gregh3269 commented 3 months ago

Hello,

I am using the tomcat plugin and have upgraded to eclipse-jee-2024-03-R-linux-gtk-x86_64 and am getting this error. I am not sure if its PDE or IDE error. The plugin works on 2023-12.

protected IJavaProject getJavaProject() throws CoreException { IProject project = (IProject) (this.getElement() .getAdapter(IProject.class)); return (IJavaProject) (project.getNature(JavaCore.NATURE_ID)); << line 237 }

[ java.lang.ClassCastException ] java.lang.ClassCastException: class org.eclipse.jdt.internal.core.JavaNature cannot be cast to class org.eclipse.jdt.core.IJavaProject (org.eclipse.jdt.internal.core.JavaNature and org.eclipse.jdt.core.IJavaProject are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @2aa7a5c1) at com.sysdeo.eclipse.tomcat.TomcatProjectPropertyPage.getJavaProject(TomcatProjectPropertyPage.java:237) at com.sysdeo.eclipse.tomcat.TomcatProjectGeneralPropertyPage.createIsTomcatProjectGroup(TomcatProjectGeneralPropertyPage.java:150) at com.sysdeo.eclipse.tomcat.TomcatProjectGeneralPropertyPage.createContents(TomcatProjectGeneralPropertyPage.java:114) at com.sysdeo.eclipse.tomcat.TomcatProjectPropertyPage.createContents(TomcatProjectPropertyPage.java:124) at org.eclipse.jface.preference.PreferencePage.createControl(PreferencePage.java:244) at org.eclipse.jface.preference.PreferenceDialog.createPageControl(PreferenceDialog.java:1433) at org.eclipse.jface.preference.PreferenceDialog$8.run(PreferenceDialog.java:1196) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47) at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174) at org.eclipse.jface.preference.PreferenceDialog.showPage(PreferenceDialog.java:1188) at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.showPage(FilteredPreferenceDialog.java:618) at org.eclipse.jface.preference.PreferenceDialog$5.lambda$0(PreferenceDialog.java:660) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67) at org.eclipse.jface.preference.PreferenceDialog$5.selectionChanged(PreferenceDialog.java:657) at org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredViewer.java:820) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47) at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174) at org.eclipse.jface.viewers.StructuredViewer.firePostSelectionChanged(StructuredViewer.java:817) at org.eclipse.jface.viewers.ColumnViewer.firePostSelectionChanged(ColumnViewer.java:1065) at org.eclipse.jface.viewers.StructuredViewer.handlePostSelect(StructuredViewer.java:1185) at org.eclipse.swt.events.SelectionListener$1.widgetSelected(SelectionListener.java:84) at org.eclipse.jface.util.OpenStrategy.firePostSelectionEvent(OpenStrategy.java:283) at org.eclipse.jface.util.OpenStrategy$1.lambda$1(OpenStrategy.java:437) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:40) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:132) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:5040) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4520) at org.eclipse.jface.window.Window.runEventLoop(Window.java:823) at org.eclipse.jface.window.Window.open(Window.java:799) at org.eclipse.ui.dialogs.PropertyDialogAction.run(PropertyDialogAction.java:154) at org.eclipse.jface.action.Action.runWithEvent(Action.java:474) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:581) at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:415) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5855) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1529) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:5065) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4517) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1151) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1042) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:152) at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:639) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:546) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:651) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:588) at org.eclipse.equinox.launcher.Main.run(Main.java:1459) at org.eclipse.equinox.launcher.Main.main(Main.java:1432)

I have done a fresh install and created a dynamic web project. The plugin has always worked before.

image

Can anybody help me here?

Cheers

laeubi commented 3 months ago

Can anybody help me here?

This is an issue of the tomcat plugin ...

gregh3269 commented 3 months ago

The plugin works on 2023-12 and has done for many years on previous editions. I have debugged it and cannot find out why it does the cast exception thing.

Maybe its the IDE causing it?

unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @2aa7a5c1)

laeubi commented 3 months ago

Just because it is doing things many year wrong has worked mean it works forever, it cast and object to an type without a typecheck and the object is not of the cast type that's what the exception says.

iloveeclipse commented 3 months ago

Please report bug for the Tomcat plugin. The code in com.sysdeo.eclipse.tomcat.TomcatProjectPropertyPage.getJavaProject() should be fixed.

gregh3269 commented 3 months ago

From this code this is all eclipse not the plugin? So its the PDE?

IProject project = (IProject) (this.getElement() .getAdapter(IProject.class)); return (IJavaProject) (project.getNature(JavaCore.NATURE_ID));

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>TestDW</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
    </natures>
</projectDescription>

image

iloveeclipse commented 3 months ago

return (IJavaProject) (project.getNature(JavaCore.NATURE_ID)); is wrong and worked before just because it happened that JavaProject was implementing IProjectNature.

This is not the case anymore. The correct way to get IJavaProject from IProject is and was something like

IProjectNature nature = project.getNature(JavaCore.NATURE_ID);
if(nature != null)
    return JavaCore.create(project);
else
    return null;
gregh3269 commented 3 months ago

Thanks @iloveeclipse. :-)