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

Joe Darcy darcy at openjdk.org
Wed Feb 4 22:41:56 UTC 2026


On Wed, 4 Feb 2026 21:45:49 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)
>
> Jonathan László Lampérth has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Add JBS ID to @bug in test

@jonath4ndev, please file a CSR for the behavior change of the PR.

(From a quick skim, it isn't clear to me if any spec update is needed as well.)

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

PR Comment: https://git.openjdk.org/jdk/pull/29550#issuecomment-3850097731


More information about the compiler-dev mailing list