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

[Enhanced switch] BootstrapMethodError: bootstrap method initialization exception switching on Boolean #3409

Open
srikanth-sankaran opened this issue Dec 6, 2024 · 2 comments

Comments

@srikanth-sankaran
Copy link
Contributor

Master:

There are at least two problems here:

  1. This code should not compile at 23, without preview enabled. It does.
  2. When run it reports:
Exception in thread "main" java.lang.BootstrapMethodError: bootstrap method initialization exception
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:188)
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:316)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:274)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:264)
	at X.main(X.java:4)
Caused by: java.lang.IllegalArgumentException: label with illegal type found: class java.lang.Boolean
	at java.base/java.lang.runtime.SwitchBootstraps.verifyLabel(SwitchBootstraps.java:172)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
	at java.base/java.lang.runtime.SwitchBootstraps.typeSwitch(SwitchBootstraps.java:156)
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:147)
	... 4 more
public class X {
 public static void main(String[] args) {
	 Boolean b = null;
	 switch (b) {
	 	case true -> System.out.println("true");
	 	case false -> System.out.println("false");
	 	case null -> System.out.println("Null");
	 }
 }
}

@srikanth-sankaran
Copy link
Contributor Author

srikanth-sankaran commented Dec 6, 2024

Confusingly, javac from JDK23 also compiles this without preview being enabled and also crashes with identical symptoms

Likewise with JDK24 early access build 26

@srikanth-sankaran
Copy link
Contributor Author

Javac from JDK21 complains:

5: error: constant label of type boolean is not compatible with switch selector type Boolean
case true -> System.out.println("true");

Likewise with javac from JDK22

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