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

DS processing crashes when Pattern matching is used in a switch statement #1440

Open
FlorianKroiss opened this issue Oct 14, 2024 · 0 comments

Comments

@FlorianKroiss
Copy link

  1. Configure a Plugin Project with Java 21 and enable DS processing.
  2. Create a service interface:
package foo;

public interface FooService {

	void doStuff(Integer input);
	
}
  1. Implement interface and add Component annotation:
package foo;

import org.osgi.service.component.annotations.Component;

@Component
public class FooServiceImpl implements FooService {

	@Override
	public void doStuff(Integer input) {
		switch(input) {
		case Integer i -> {} // java.lang.UnsupportedOperationException: Operation only supported in JLS21 AST
		//default -> {} // works
		}
	}

}

An error message pops up when saving the file:

Errors occurred during the build.
Errors running builder 'Java Builder' on project 'Dummy'.
Operation only supported in JLS21 AST

From the Error Log:

java.lang.UnsupportedOperationException: Operation only supported in JLS21 AST
	at org.eclipse.jdt.core.dom.ASTNode.supportedOnlyIn21(ASTNode.java:2587)
	at org.eclipse.jdt.core.dom.Pattern.<init>(Pattern.java:42)
	at org.eclipse.jdt.core.dom.NullPattern.<init>(NullPattern.java:66)
	at org.eclipse.jdt.core.dom.ASTConverter.createFakeNullPattern(ASTConverter.java:4883)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2941)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2039)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1486)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3197)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3334)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3221)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:813)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:208)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3567)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1595)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1052)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:739)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver$ECJCompilationUnitResolver.resolve(CompilationUnitResolver.java:111)
	at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:968)
	at org.eclipse.pde.ds.internal.annotations.DSAnnotationCompilationParticipant.processAnnotations(DSAnnotationCompilationParticipant.java:717)
	at org.eclipse.pde.ds.internal.annotations.DSAnnotationCompilationParticipant.processAnnotations(DSAnnotationCompilationParticipant.java:653)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.processAnnotations(AbstractImageBuilder.java:770)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:383)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:79)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:286)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:198)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:207)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:300)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

I did not dig into the problem to much, but I suppose the hard-coded JLS4 Constant is a part of the problem:

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

No branches or pull requests

1 participant