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

Rule cases in switch expression accepted even if complete normally

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 12
    • Fix Version/s: 12
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b21
    • Verification:
      Verified

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: