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

[lworld] final field initialization bug with instance block initializers

XMLWordPrintable

      In a value class, a blank final instance variable must be definitely assigned after the argument list of an explicit superclass constructor invocation (8.8.7.1).

                      https://cr.openjdk.org/~dlsmith/jep401/jep401-20240624/specs/value-objects-jls.html#jls-8.3.1.2

                     Test Code:
                      value class ValueClass {
                        int f;
                       {
                              f = 7;
                       }
                       public int get() { return f; }
                    }

      The Valhalla java runtime throws the below error. In jdk23, normal class this final field was initialized successfully.
          java --enable-preview TestCls

      Exception in thread "main" java.lang.VerifyError: Illegal use of putfield on a strict field
      Exception Details:
                      Location:
                      ValueClass.<init>()V @7: putfield
                      Reason:
                      Error exists in the bytecode
                      Bytecode:
                       0000000: 2ab7 0001 2a10 07b5 0007 b1
                      at TestCls.main(TestCls.java:16)

      Reported by: Sivakumar Gurusamy

            vromero Vicente Arturo Romero Zaldivar
            vromero Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: