[lworld] RFR: 8369062: [lworld] Do not allow references to instance fields before a this() invocation

Vicente Romero vromero at openjdk.org
Sun Oct 5 21:04:16 UTC 2025


On Sat, 4 Oct 2025 05:36:26 GMT, Chen Liang <liach at openjdk.org> wrote:

>> implementation of [1] in valhalla. This means that code like:
>> 
>> class Inner7 {
>>     private int x;
>> 
>>     public Inner7(byte y) {
>>         x = y;  // error can't refer to an instance field before a this() invocation
>>         this((int)y);
>>     }
>>     public Inner7(int x) {
>>         this.x = x;
>>         super();
>>     }
>> }
>> 
>> 
>> won't be accepted by javac
>> [1] https://bugs.openjdk.org/browse/JDK-8368719
>
> Comment in JDK-8368719 says we don't want error unless JEP 401 is previewed and compilation is done with preview enabled. I think what we have (failing for pre-this immediately without preview on) is probably better, but we just need to make sure Dan or whoever is aware of our decisions.

@liach thanks for the review

-------------

PR Comment: https://git.openjdk.org/valhalla/pull/1659#issuecomment-3369325068


More information about the valhalla-dev mailing list