Inconsistent stackmap frames when using nested switch expressions with record patterns

XMLWordPrintable

    • generic

      ADDITIONAL SYSTEM INFORMATION :

      A DESCRIPTION OF THE PROBLEM :
      Hi, a VerifyError triggers at runtime when executing a method that combines an initial "instanceof" record pattern binding with a subsequent nested switch expression using sealed interface patterns.

      Discovered on openjdk 25.0.1, but also errors on openjdk 25.0.2 and openjdk 21.0.9

      Let me know if i can supply more info.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Save provided source code to disk as Repro.java
      2. Compile and run using `java Repro.java`
      3. Observe VerifyError at runtime

      ---------- BEGIN SOURCE ----------
      public class Repro {
          sealed interface Result permits Ok, Err {}
          record Ok(Object v) implements Result {}
          record Err(Object e) implements Result {}

          Result getRes() { return new Ok("test"); }

          Result trigger() {
              if (getRes() instanceof Err(var e)) return new Err(e);

              return switch (getRes()) {
                  case Err e -> e;
                  case Ok v1 -> switch (getRes()) {
                      case Err e -> e;
                      case Ok v2 -> new Ok("win");
                  };
              };
          }

          public static void main(String[] args) {
              System.out.println(new Repro().trigger());
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Refactor the logic to avoid nested expressions by moving the inner switch to a separate method or use a functionalesque flatMap method to handle the Result types

      FREQUENCY :
      ALWAYS

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: