Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8334139

Compilation error when using patterns in switch statements

XMLWordPrintable

    • x86_64
    • windows

      ADDITIONAL SYSTEM INFORMATION :
      Intel i/-12700F
      Windows 11 23H2
      Android Studio Jellyfish 2023.3.1 Patch 1


      A DESCRIPTION OF THE PROBLEM :
      Recently discovered the new patterns in Java 21 and decided to try it out in an Android project. However, compilation fails with the following error
      com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.lang.runtime.SwitchBootstraps not found

      As long as I remove the pattern matching to types, the project compiles. See the "Source code for an executable test case" I have provided below.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use code below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code compiles
      ACTUAL -
      Code fails to compile

      ---------- BEGIN SOURCE ----------
      public class Reproducable {
          static <T> void test(T value) {
              switch (value) {
                  case Integer i -> System.out.println("Integer");
                  case Float f -> System.out.println("Float");
                  case Boolean b -> System.out.println("Boolean");
                  default -> System.out.println("Some other type");
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No workaround, going to go back to good old if-else statements.

      FREQUENCY : always


            rkale Raghu Kale
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: