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

Bug with compiling with javac a switch case.

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      only tested on Ubuntu 22.04.2 LTS.

      A DESCRIPTION OF THE PROBLEM :
      when tried to compile a code with a switch case, a bug pops up.


      REGRESSION : Last worked in version 18

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      class Main{

              public static void main(String ... args){

              String operator = "+";
              String writtenOperator = (switch(operator){
                      case "+" -> "PLUS";
                      case "-" -> "Minus";
                      default -> "Unbekannter Operator";
              }).toUpperCase();
              System.out.printf("%s\n", writtenOperator);
              }
      }


      then just try to compile with: javac Main.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The result should be in this case just a "PLUS"
      ACTUAL -
      result can only be seen if its not compiled but directly interpreted with:
      java Main.java

      ---------- BEGIN SOURCE ----------
      see steps to reproduce.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      see Actual Result. or with If-else.


      FREQUENCY : always


            adev Anupam Dev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: