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

Chen Liang liach at openjdk.org
Tue Dec 9 17:17:10 UTC 2025


On Tue, 9 Dec 2025 02:38:06 GMT, Vicente Romero <vromero 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.

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

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


More information about the valhalla-dev mailing list