RFR: 8344706: Compiler Implementation of Compact Source Files and Instance Main Methods [v4]
Jan Lahoda
jlahoda at openjdk.org
Wed Apr 23 15:23:56 UTC 2025
On Tue, 22 Apr 2025 10:14:44 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> src/java.base/share/classes/jdk/internal/misc/MethodFinder.java line 89:
>>
>>> 87: if (mainMethod == null) {
>>> 88: //if not public method, try to lookup a non-public one
>>> 89: mainMethod = JLA.findMethod(cls, false, "main", String[].class);
>>
>> Is there a reason why the first findMethod can't use publicOnly=false?
>
> My reason was that when `publicOnly=false`, there's more classloading happening (unsurprisingly, as also the non-public methods must be resolved). Which may lead to a change of behavior if the traditional `public static main(String[])` exists.
>
> IIRC there is a test relying on this behavior, but I don't have the name offhand. Will put it here when I have it.
>
> For example:
>
> $ cat Main.java
> public class Main {
> public static void main(String... args) {
> System.err.println("Hello!");
> }
> private Missing get() { return null; }
> }
> $ cat Missing.java
> public class Missing {
> }
> $ jdk-24/bin/javac Main.java Missing.java; rm Missing.class
> $ jdk-24/bin/java -classpath . Main
> Hello!
> $ jdk-without-publicOnly=true/bin/java -classpath . Main
> Error: Unable to initialize main class Main
> Caused by: java.lang.NoClassDefFoundError: Missing
The tests that would be affected by the extra classloading appear to be:
test/jdk/java/lang/System/SecurityManagerWarnings.java
test/jdk/java/lang/System/LoggerFinder/SignedLoggerFinderTest/SignedLoggerFinderTest.java
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24438#discussion_r2056303456
More information about the compiler-dev
mailing list