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

Jonathan László Lampérth jlamperth at openjdk.org
Wed Feb 18 14:23:05 UTC 2026


> 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)

Jonathan László Lampérth has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Merge remote-tracking branch 'upstream/master' into 8376534
 - Add JBS ID to @bug in test
 - Ensure source launcher instantiates correct class for inherited main

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/29550/files
  - new: https://git.openjdk.org/jdk/pull/29550/files/8adfad3e..6fade70f

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=29550&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=29550&range=01-02

  Stats: 41436 lines in 971 files changed: 21305 ins; 5956 del; 14175 mod
  Patch: https://git.openjdk.org/jdk/pull/29550.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/29550/head:pull/29550

PR: https://git.openjdk.org/jdk/pull/29550


More information about the compiler-dev mailing list