8031494: [launcher] java launcher should check for JNI Pending exceptions.
authorksrini
Tue, 14 Jan 2014 13:19:11 -0800
changeset 22279 877c94f9476b
parent 22278 a32375f9a4b5
child 22280 384c863b2462
8031494: [launcher] java launcher should check for JNI Pending exceptions. Reviewed-by: alanb, chegar, mchung
jdk/src/share/bin/java.c
jdk/src/windows/bin/java_md.c
--- a/jdk/src/share/bin/java.c	Tue Jan 14 14:27:03 2014 -0500
+++ b/jdk/src/share/bin/java.c	Tue Jan 14 13:19:11 2014 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -345,6 +345,13 @@
         } \
     } while (JNI_FALSE)
 
+#define CHECK_EXCEPTION_RETURN(CER_return_value) \
+    do { \
+        if ((*env)->ExceptionOccurred(env)) { \
+            return CER_return_value; \
+        } \
+    } while (JNI_FALSE)
+
 int JNICALL
 JavaMain(void * _args)
 {
@@ -1233,8 +1240,9 @@
                 "checkAndLoadMain",
                 "(ZILjava/lang/String;)Ljava/lang/Class;"));
 
-    str = NewPlatformString(env, name);
-    result = (*env)->CallStaticObjectMethod(env, cls, mid, USE_STDERR, mode, str);
+    NULL_CHECK0(str = NewPlatformString(env, name));
+    NULL_CHECK0(result = (*env)->CallStaticObjectMethod(env, cls, mid,
+                                                        USE_STDERR, mode, str));
 
     if (JLI_IsTraceLauncher()) {
         end   = CounterGet();
@@ -1480,7 +1488,7 @@
     NULL_CHECK(cls);
     NULL_CHECK(showSettingsID = (*env)->GetStaticMethodID(env, cls,
             "showSettings", "(ZLjava/lang/String;JJJZ)V"));
-    joptString = (*env)->NewStringUTF(env, optString);
+    NULL_CHECK(joptString = (*env)->NewStringUTF(env, optString));
     (*env)->CallStaticVoidMethod(env, cls, showSettingsID,
                                  USE_STDERR,
                                  joptString,
@@ -1521,31 +1529,35 @@
     NULL_CHECK(printHelp = (*env)->GetStaticMethodID(env, cls,
                                         "printHelpMessage", "(Z)V"));
 
-    jprogname = (*env)->NewStringUTF(env, _program_name);
+    NULL_CHECK(jprogname = (*env)->NewStringUTF(env, _program_name));
 
     /* Initialize the usage message with the usual preamble */
     (*env)->CallStaticVoidMethod(env, cls, initHelp, jprogname);
+    CHECK_EXCEPTION_RETURN();
 
 
     /* Assemble the other variant part of the usage */
     if ((knownVMs[0].flag == VM_KNOWN) ||
         (knownVMs[0].flag == VM_IF_SERVER_CLASS)) {
-      vm1 = (*env)->NewStringUTF(env, knownVMs[0].name);
-      vm2 =  (*env)->NewStringUTF(env, knownVMs[0].name+1);
+      NULL_CHECK(vm1 = (*env)->NewStringUTF(env, knownVMs[0].name));
+      NULL_CHECK(vm2 =  (*env)->NewStringUTF(env, knownVMs[0].name+1));
       (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2);
+      CHECK_EXCEPTION_RETURN();
     }
     for (i=1; i<knownVMsCount; i++) {
       if (knownVMs[i].flag == VM_KNOWN) {
-        vm1 =  (*env)->NewStringUTF(env, knownVMs[i].name);
-        vm2 =  (*env)->NewStringUTF(env, knownVMs[i].name+1);
+        NULL_CHECK(vm1 =  (*env)->NewStringUTF(env, knownVMs[i].name));
+        NULL_CHECK(vm2 =  (*env)->NewStringUTF(env, knownVMs[i].name+1));
         (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2);
+        CHECK_EXCEPTION_RETURN();
       }
     }
     for (i=1; i<knownVMsCount; i++) {
       if (knownVMs[i].flag == VM_ALIASED_TO) {
-        vm1 =  (*env)->NewStringUTF(env, knownVMs[i].name);
-        vm2 =  (*env)->NewStringUTF(env, knownVMs[i].alias+1);
+        NULL_CHECK(vm1 =  (*env)->NewStringUTF(env, knownVMs[i].name));
+        NULL_CHECK(vm2 =  (*env)->NewStringUTF(env, knownVMs[i].alias+1));
         (*env)->CallStaticVoidMethod(env, cls, vmSynonym, vm1, vm2);
+        CHECK_EXCEPTION_RETURN();
       }
     }
 
@@ -1558,8 +1570,9 @@
         defaultVM = knownVMs[0].server_class+1;
       }
 
-      vm1 =  (*env)->NewStringUTF(env, defaultVM);
+      NULL_CHECK(vm1 =  (*env)->NewStringUTF(env, defaultVM));
       (*env)->CallStaticVoidMethod(env, cls, vmErgo, isServerClassMachine,  vm1);
+      CHECK_EXCEPTION_RETURN();
     }
 
     /* Complete the usage message and print to stderr*/
--- a/jdk/src/windows/bin/java_md.c	Tue Jan 14 14:27:03 2014 -0500
+++ b/jdk/src/windows/bin/java_md.c	Tue Jan 14 13:19:11 2014 -0800
@@ -1475,7 +1475,7 @@
 
     // expand the arguments that require expansion, the java method will strip
     // out the indicator character.
-    inArray = NewPlatformStringArray(env, nargv, argc);
+    NULL_CHECK0(inArray = NewPlatformStringArray(env, nargv, argc));
     outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray);
     for (i = 0; i < argc; i++) {
         JLI_MemFree(nargv[i]);