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

VerifyError is thrown at runtime for a local record with a static factory method

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      $ uname -a
      Linux skylake 5.10.0-11-amd64 #1 SMP Debian 5.10.92-1 (2022-01-18) x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Running the example code causes a VerifyError "Bad type on operand stack" to be thrown, even though it compiles successfully.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the sample code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected no output, and exit status of 0.
      ACTUAL -
      Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
      Exception Details:
        Location:
          TestLocalRecordInInnerClassMethod$Inner$1Record.create(Ljava/lang/Object;)LTestLocalRecordInInnerClassMethod$Inner$1Record; @6: getfield
        Reason:
          Type 'java/lang/Object' (current frame, stack[3]) is not assignable to 'TestLocalRecordInInnerClassMethod$Inner$1Record'
        Current Frame:
          bci: @6
          flags: { }
          locals: { 'java/lang/Object' }
          stack: { uninitialized 0, uninitialized 0, 'java/lang/Object', 'java/lang/Object' }
        Bytecode:
          0000000: bb00 0259 2a2a b400 01b7 0011 b0

      at TestLocalRecordInInnerClassMethod$Inner.<init>(TestLocalRecordInInnerClassMethod.java:11)
      at TestLocalRecordInInnerClassMethod.main(TestLocalRecordInInnerClassMethod.java:16)

      Process finished with exit code 1


      ---------- BEGIN SOURCE ----------
      public class TestLocalRecordInInnerClassMethod {
        class Inner {
          Inner() {
            record Record(Object o) {
              // Commenting out the following line removes the VerifyError
              static Record create(Object obj) { return new Record(obj); }

              // POSSIBLY RELATED:
              // Uncommenting the following line causes a compilation error: "java: Compilation failed: internal java compiler error"
              // static Record create() { return new Record("hi"); }
            }
            new Record("hi");
          }
        }

        public static void main(String[] args) {
          new TestLocalRecordInInnerClassMethod().new Inner();
        }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            vromero Vicente Arturo Romero Zaldivar
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: