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

Rule cases in switch expression accepted even if complete normally

XMLWordPrintable

    • b21
    • Verified

      As reported here:
      http://mail.openjdk.java.net/pipermail/amber-dev/2018-October/003601.html

      This code:
      ---
      public class SwitchBug {

          static String hold(String item) {
              return switch(item) {
                  case String s -> { System.out.println(s); }
                  default -> "temp";
              };
          }

          public static void main(String[] args) {
              System.out.println(hold("bug"));
          }
      }
      ---

      compiles and produces:
      ---
      bug
      temp
      ---

      This program should not compile, as the first case completes normally.

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: