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

Compiler erronousely allows access to instance variable in argument expression of a constructor invocation

XMLWordPrintable

    • b26
    • b03

        This code compiles in with JDK 23 b 26 with disabled preview:

        class clss21717_b {
            int field1 = 666;

            clss21717_b(int arg) {
                field1 = arg;
            }
        }

        class clss21717_a extends clss21717_b {
            int field2;

            clss21717_a() {
                super(field2 = 1); //supposed to fall here
            }
        }

        JEP 482 allows such assignment, but JEP 482 is a preview feature. This code should fail in non-preview mode, which it does with JDKb25 but does not with JDKb26.

              acobbs Archie Cobbs
              eananeva Ella Ananeva
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: