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

Switch expression causes infinite loop

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 23
    • 22, 23
    • tools
    • None

      Running the following code snippet on current JDK causes an infinite loop:

      class Scratch {
        public static int matcher(Object l, Object r) {
          record Pair(Object left, Object right) { }
          return switch (new Pair(l, r)) {
            case Pair(Byte b, var $$) -> 1;
            case Pair(var $, Byte str) -> 1;
            default -> -1;
          };
        }

        public static void main(String[] args) {
          System.out.println(matcher(null, "1"));
        }
      }

      This was originally reported here: https://github.com/SAP/SapMachine/issues/1571

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

              Created:
              Updated:
              Resolved: