RFR: 8376534: Source launcher instantiates wrong class on inherited instance main

Chen Liang liach at openjdk.org
Wed Feb 4 05:05:27 UTC 2026


On Tue, 3 Feb 2026 20:46:06 GMT, Jonathan László Lampérth <jlamperth at openjdk.org> wrote:

> Fix a bug where, for inherited instance main methods, the source launcher attempts to invoke main on an instance of the superclass/superinterface that declares main, instead of on an instance of the inheriting class.
> 
> <details closed>
>   <summary>Failure Example</summary>
> 
> 
> // A.java
> class A extends B {}
>> // B.java
> class B {
>     void main() {
>         System.out.println(getClass().getName());
>     }
> }
> 
> 
> 
> $ java A.java
> B // expected "A" here
>> $ java B.java
> B
> ``` 
> </details>
> 
> Note: There is still an issue with inheriting main from a different package in modular mode, which will be handled separately [JDK-8377010](https://bugs.openjdk.org/browse/JDK-8377010)

Good. For [JDK-8377010](https://bugs.openjdk.org/browse/JDK-8377010), I recommend using MethodHandles.lookup for resolution of members inherited across modules.

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

Marked as reviewed by liach (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/29550#pullrequestreview-3748985899


More information about the compiler-dev mailing list