On 30/06/2016 5:37 PM, Peter Levart wrote:
Hi Mandy,

The following patch:

--- old/src/java.base/share/native/libjli/java.c    2016-06-30
09:32:59.519839770 +0200
+++ new/src/java.base/share/native/libjli/java.c    2016-06-30
09:32:59.458839421 +0200
@@ -476,15 +476,6 @@
      */
     PostJVMInit(env, appClass, vm);
     CHECK_EXCEPTION_LEAVE(1);
-    /*
-     * The LoadMainClass not only loads the main class, it will also
ensure
-     * that the main method's signature is correct, therefore further
checking
-     * is not required. The main method is invoked here so that
extraneous java
-     * stacks are not in the application stack trace.
-     */
-    mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
-                                       "([Ljava/lang/String;)V");
-    CHECK_EXCEPTION_NULL_LEAVE(mainID);

     /* Build platform specific argument array */
     mainArgs = CreateApplicationArgs(env, argv, argc);
@@ -493,6 +484,16 @@
     if (dryRun) {
         ret = 0;
     } else {
+        /*
+         * The LoadMainClass not only loads the main class, it will
also ensure
+         * that the main method's signature is correct, therefore
further checking
+         * is not required. The main method is invoked here so that
extraneous java
+         * stacks are not in the application stack trace.
+         */
+        mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
+ "([Ljava/lang/String;)V");
+        CHECK_EXCEPTION_NULL_LEAVE(mainID);
+
         /* Invoke main method. */
         (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);



...that just moves the call to GetStaticMethodID to inside the else
branch of if (dryRun) statement fixes the problem. The presence and
conformance of main method is already verified by LaucherHelper in a way
that doesn't initialize the main class. It's just GetStaticMethodID that
causes its initialization.

I had assumed that initialization was desirable as part of checking that everything was specified correctly. If not then --dry-run would seem to do very little compared to just running -version, and so doesn't really seem to carry its weight.

Cheers,
David



Regards, Peter



On 06/30/2016 08:43 AM, Peter Levart wrote:
On 06/30/2016 08:32 AM, Peter Levart wrote:
But is it possible to check for the presence of a method in a class
without initializing it? Maybe the check for the presence of main
method could simply be dropped out of --dry-run?

It seems that it *is* possible to check for the presence of a method
without initializing the class. The following:

public class Test {

    static class Nested {
        static {
            System.out.println("Hello from Nested.<clinit>");
        }

        static void m() {}
    }

    public static void main(String[] args) throws Exception {
        System.out.println(Nested.class.getDeclaredMethod("m"));
    }
}


...prints just:

static void Test$Nested.m()



Regards, Peter


Reply via email to