[lworld] RFR: 8367323: [lworld] javac is rejecting valid code after fix for JDK-8359370

Chen Liang liach at openjdk.org
Fri Sep 12 15:18:53 UTC 2025


On Thu, 11 Sep 2025 02:14:37 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> Recent fix for [JDK-8359370](https://bugs.openjdk.org/browse/JDK-8359370) introduced a minor bug. This code should be accepted by javac:
> 
> class SuperClass<T> {
>     public SuperClass(Object o) {}
> }
> 
> class Sub<T> extends SuperClass<T> {
>     public Sub() {
>         super(new Object() {
>             void foo() {
>                 getClass();
>             }
>         });
>     }
> }
> 
> 
> but it is currently rejected as the `getClass` invocation is considered to be an invocation of an instance method of class `Sub`

Looks like a very neat solution, thanks so much!

Does the problem still happen without the patch if the method call is to a method that is not present on the outer class? I wonder if we should tweak the `sym.isMemberOf(env.enclClass.sym, types)` part.

Wonder if this can help the bot fetch the JBS issue.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1276:

> 1274: 
> 1275:         boolean insideLambda = false;
> 1276:         boolean insideClassDef = false;

We can revert this split of insideLambda and insideClassDef now.

test/langtools/tools/javac/SuperInit/SuperInitFails.out line 21:

> 19: SuperInitFails.java:180:18: compiler.err.cant.ref.before.ctor.called: x
> 20: SuperInitFails.java:186:32: compiler.err.cant.ref.before.ctor.called: x
> 21: SuperInitFails.java:195:36: compiler.err.cant.ref.before.ctor.called: xx

We should update the comment at https://github.com/openjdk/valhalla/blob/63649dca75abe099fedebbe14140d0da46fda5ea/test/langtools/tools/javac/SuperInit/SuperInitFails.java#L195 to something like:

> // this should resolve to the anonymous class's inherited xx fields

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

Marked as reviewed by liach (Committer).

PR Review: https://git.openjdk.org/valhalla/pull/1567#pullrequestreview-3213577511
PR Comment: https://git.openjdk.org/valhalla/pull/1567#issuecomment-3277537982
PR Comment: https://git.openjdk.org/valhalla/pull/1567#issuecomment-3285677684
PR Review Comment: https://git.openjdk.org/valhalla/pull/1567#discussion_r2341912903
PR Review Comment: https://git.openjdk.org/valhalla/pull/1567#discussion_r2341911196


More information about the valhalla-dev mailing list