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

[JEP 488][Preview][Primitive Patterns] ECJ crashes compiling switch over void typed selector expression #3369

Open
srikanth-sankaran opened this issue Nov 29, 2024 · 2 comments
Assignees

Comments

@srikanth-sankaran
Copy link
Contributor

Found by code inspection and white box testing:

ECJ crashes compiling the following code; javac complains error: the switch statement does not cover all possible input values

public class X {
	public static void main(String[] args) {
		switch (main(null)) {
		
		}
	}
}

Stack trace on master (problem can be seen from 4.34 M2)

Caused by: java.util.EmptyStackException
	at java.base/java.util.Stack.peek(Stack.java:103)
	at org.eclipse.jdt.internal.compiler.codegen.OperandStack.peek(OperandStack.java:123)
	at org.eclipse.jdt.internal.compiler.codegen.CodeStream.dup(CodeStream.java:1082)
	at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCodeSwitchPatternPrologue(SwitchStatement.java:850)
	at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCode(SwitchStatement.java:708)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:395)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:331)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:773)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:843)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:403)
	at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:1119)
	at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:1155)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:292)
@srikanth-sankaran
Copy link
Contributor Author

srikanth-sankaran commented Nov 29, 2024

From a cursory reading of JEP488 and Draft JLS changes I haven't been able to ascertain the right behavior here:

14.11 has been modified to say The type of the selector expression may be any type. and then if it is void what ? I haven't been able to determine.

@srikanth-sankaran
Copy link
Contributor Author

Not sure this should compile, but does with both javac and ECJ:

public class X {
	public static void main(String[] args) {
		switch (null) {
			case null -> System.out.println("Null");
			default-> System.out.println("Default");
		}
	}
}

Not sure this should not (two nots there) compile, but doesn't with both ECJ and javac: Both complain about missing default

public class X {
	public static void main(String[] args) {
		switch (null) {
			case null -> System.out.println("Null");
			// default-> System.out.println("Default");
		}
	}
}

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

2 participants