Integrated: 8376534: Source launcher instantiates wrong class on inherited instance main
Jonathan László Lampérth
jlamperth at openjdk.org
Wed Feb 18 21:57:12 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)
This pull request has now been integrated.
Changeset: c8338be9
Author: Jonathan László Lampérth <jlamperth at openjdk.org>
Committer: Chen Liang <liach at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/c8338be9ad455445a94972d2d9e483a24adc27cf
Stats: 63 lines in 2 files changed: 51 ins; 4 del; 8 mod
8376534: Source launcher instantiates wrong class on inherited instance main
Reviewed-by: liach, cstein
-------------
PR: https://git.openjdk.org/jdk/pull/29550
More information about the compiler-dev
mailing list