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

Nested record deconstruction cause bytecode error

XMLWordPrintable

    • 20
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows11, jdk-20_windows-x64_bin

      A DESCRIPTION OF THE PROBLEM :
      Source code:

      public class RecordDeconstructTest {
          record P(int x, int y) {}
          sealed interface IShape permits Circle {}
          record Circle(P c, int r) implements IShape {}
          public static int getMinY(IShape shape) {
              return switch (shape) {
                  case Circle(var __, var r)when r < 0 -> throw new IllegalArgumentException();
                  case Circle(var p, var r) -> p.y - r;
                  default -> throw new RuntimeException();
              };
          }
          public static void main(String[] args) {}
      }

      With using "--enable-preview" command, these code run well in jdk19.
      In jdk20, the code can be compiled but failed to run. The following is the error message:

      Error: Unable to initialize main class RecordDeconstructTest
      Caused by: java.lang.VerifyError: Bad type on operand stack
      Exception Details:
        Location:
          RecordDeconstructTest.getMinY(LRecordDeconstructTest$IShape;)I @125: getfield
        Reason:
          Type 'RecordDeconstructTest$Circle' (current frame, stack[0]) is not assignable to 'RecordDeconstructTest$P'
        Current Frame:
          bci: @125
          flags: { }
          locals: { 'RecordDeconstructTest$IShape', 'RecordDeconstructTest$IShape', integer, 'RecordDeconstructTest$Circle', top, top, 'RecordDeconstructTest$P', integer }
          stack: { 'RecordDeconstructTest$Circle' }
        Bytecode:
          0000000: 2a59 b800 0757 4c03 3d2b 1cba 000d 0000
          0000010: ab00 0000 0000 0076 0000 0001 0000 0000
          0000020: 0000 0014 2bc0 0011 4e2d b600 133a 0603
          0000030: 3607 1906 1507 ba00 1700 00ab 0000 0041
          0000040: 0000 0002 ffff ffff 0000 0041 0000 0000
          0000050: 0000 0019 1906 3a04 2db6 0018 3608 1508
          0000060: 3605 121c bb00 1e59 b700 20a5 0009 0436
          0000070: 07a7 ffc1 bb00 2159 b700 23bf 2db4 0024
          0000080: 1504 64a7 000b bb00 2a59 b700 2cbf ac4c
          0000090: bb00 2f59 2bb6 0031 2bb7 0035 bf
        Exception Handler Table:
          bci [42, 45] => handler: 143
          bci [89, 92] => handler: 143
        Stackmap Table:
          append_frame(@9,Object[#70],Integer)
          same_frame(@36)
          full_frame(@50,{Object[#70],Object[#70],Integer,Object[#17],Top,Top,Object[#37],Integer},{})
          same_frame(@84)
          full_frame(@116,{Object[#70],Object[#70],Integer,Object[#17],Object[#37],Integer,Object[#37],Integer},{})
          full_frame(@124,{Object[#70],Object[#70],Integer,Object[#17],Top,Top,Object[#37],Integer},{})
          full_frame(@134,{Object[#70],Object[#70],Integer},{})
          full_frame(@142,{Object[#70]},{Integer})
          same_locals_1_stack_item_frame(@143,Object[#45])

      REGRESSION : Last worked in version 19.0.2


      FREQUENCY : always


            jlahoda Jan Lahoda
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: