RFR: 8329420: Java 22 (and 23) launcher calls default constructor although main() is static [v2]

David Holmes dholmes at openjdk.org
Wed Apr 17 07:42:00 UTC 2024


On Tue, 16 Apr 2024 13:26:43 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> src/java.base/share/native/libjli/java.c line 419:
>> 
>>> 417: invokeInstanceMainWithArgs(JNIEnv *env, jclass mainClass, jobjectArray mainArgs) {
>>> 418:     jmethodID constructor = (*env)->GetMethodID(env, mainClass, "<init>", "()V");
>>> 419:     CHECK_EXCEPTION_FAIL();
>> 
>> Shouldn't this also not be checked until you know you have an instance method?
>
> You mean to first check whether the method exists, and only then try to lookup the constructor? Not sure if that has observable effects, but I can do that.
> 
> I missed [JDK-8329581](https://bugs.openjdk.org/browse/JDK-8329581) before, my plan is to adjust this "check for exception and clear it" check to only work for `NoSuchMethodError`, and let the exception pass for any other exception.

Yes that is what I meant. If the main method is static then the class need not have any such constructor (unless that is part of the spec for this functionality?).

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18753#discussion_r1568370439


More information about the core-libs-dev mailing list