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

[lworld] javac is issuing a compiler error for a method that just sets a strict field

XMLWordPrintable

      when compiling this code:

      import jdk.internal.vm.annotation.*;

      value class Point {
          Point(int i, int j) {}
      }

      class Parent {
          @Strict
          @NullRestricted
          Point fp = new Point(1, 2); /* Flattenable and flattened inline field */

          public void setFp(Point p) { fp = p; }
      }

      javac is failing with:

      myTests/StrictFieldsError.java:12: error: cannot assign to fp after supertype constructor has been called
          public void setFp(Point p) { fp = p; }
                                       ^
      Note: myTests/StrictFieldsError.java uses preview features of Java SE 25.
      Note: Recompile with -Xlint:preview for details.
      1 error

      command:
      build/langtools/bin/javac -d out --enable-preview -source 25 --add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED myTests/StrictFieldsError.java

      this code should be accepted by the compiler

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

              Created:
              Updated:
              Resolved: