Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not create AST on opening AST view #1985

Open
noopur2507 opened this issue Jan 28, 2025 · 5 comments
Open

Could not create AST on opening AST view #1985

noopur2507 opened this issue Jan 28, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@noopur2507
Copy link
Member

noopur2507 commented Jan 28, 2025

package nn;

public class ZZ {
	public void foo(Integer n) {
		switch (n) {
		case Integer x when x.equals(10) -> {
		}
		case Comparable<?> y -> {
		}
		}
		;
	}
}
  • Open a Java file with the above code.
  • Open AST view.
  • The following exception was thrown:
org.eclipse.core.runtime.CoreException: Could not create AST:
Operation only supported in JLS21 AST
	at org.eclipse.jdt.astview.views.ASTView.internalSetInput(ASTView.java:562)
	at org.eclipse.jdt.astview.views.ASTView.refreshAST(ASTView.java:1132)
	at org.eclipse.jdt.astview.views.ASTView.setASTLevel(ASTView.java:1143)
	at org.eclipse.jdt.astview.views.ASTView$ASTLevelToggle.run(ASTView.java:186)
	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:91)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4660)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1657)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1680)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1665)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1394)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4427)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4003)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showMenu(StackRenderer.java:1436)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer$1.widgetSelected(StackRenderer.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:4660)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1657)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1680)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1665)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1394)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4427)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4003)
	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:153)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:665)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:573)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:178)
	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.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:668)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:605)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1481)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1454)
@jukzi jukzi added the bug Something isn't working label Jan 28, 2025
@jukzi
Copy link
Contributor

jukzi commented Jan 28, 2025

@noopur2507 there should be a RuntimeException as rootcause, please add its stacktrace

@iloveeclipse
Copy link
Member

I can't reproduce (I've tested with Java 21). I assume project compliance is too low.
@akurtakov : related to your latest changes?

@akurtakov
Copy link
Contributor

I will take a look.

@akurtakov
Copy link
Contributor

Just tested in 4.34 and the error happens there so not a regression in this cycle.
What I used to reproduce is have a Java 21 project with the given source file, open the ast view on it, choose ast level 17.
I've tried on Eclipse 4.34 valid java 17 switch expression on Java 11 AST:

package nn;

public class ZZ {
	public enum Day {
		SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;
	}

	public void foo(Integer n) {
		Day day = Day.MONDAY;
		int numLetters = switch (day) {
        case MONDAY, FRIDAY, SUNDAY -> {
            System.out.println(6);
            yield 6;
        }
        default -> {
            throw new IllegalStateException("Invalid day: " + day);
        }
    };  
	}
}

which led to MethodDeclaration being marked malformed.

Image

Java 21 features seems to not be handled that gracefully.

@akurtakov
Copy link
Contributor

Isssue comes from call of unsupported . Most likely due to supportedOnlyIn19()->supportedOnlyIn20()->supportedOnlyIn21() changes in NullPattern (e.g. eclipse-jdt/eclipse.jdt.core#627) that haven't been accompanied with corresponding ASTConverter adjustment.
I might be able to look into this more once the AST business streamlines a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants