[lworld] RFR: 8370635: [lworld] TypeName.super.[TypeArguments] Identifier cannot occur in prologue

Vicente Romero vromero at openjdk.org
Mon Dec 15 18:49:50 UTC 2025


On Tue, 9 Dec 2025 17:14:29 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Code like:
>> 
>> class Test {
>>     static boolean testMethod() { return true; }
>>     Test() {}
>>     Test(int a) {
>>         Test.this.testMethod();
>>         this();
>>     }
>> }
>> 
>> 
>> or:
>> 
>> 
>> class Super {
>>     static <T> void m() {}
>> }
>> 
>> class Test extends Super {
>>     Test() {
>>         Test.super.<String>m();
>>         super();
>>     }
>> }
>> 
>> 
>> shouldn't be allowed in prologue. Javac was not checking static method invocations in the prologue correctly. This fix should solve this issue,
>> 
>> TIA
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1575:
> 
>> 1573:                     sym.isMemberOf(env.enclClass.sym, types) &&
>> 1574:                     ((sym.flags() & STATIC) == 0 ||
>> 1575:                     (sym.kind == MTH && tree instanceof JCFieldAccess))) {
> 
> Is there a reason we only restrict MTH? We can write code like:
> 
> class A { static int a = 5; }
> class B extends A { B() { IO.println(B.super.a); } }
> 
> Wonder if we should block `B.super.a` style stuff in early construction.

I assume the reason is that super class initialization code, that sets the static fields in the super class, will be executed way before this super constructor invocation.

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

PR Review Comment: https://git.openjdk.org/valhalla/pull/1779#discussion_r2620466408


More information about the valhalla-dev mailing list