From f855923c6a4718a5ea28b039f02101fd1cee0700 Mon Sep 17 00:00:00 2001 From: Kumar Srinivasan Date: Tue, 14 Jan 2014 13:19:11 -0800 Subject: [PATCH] 8031494: [launcher] java launcher should check for JNI Pending exceptions Reviewed-by: alanb, chegar, mchung --- jdk/src/share/bin/java.c | 37 +++++++++++++++++++++++------------ jdk/src/windows/bin/java_md.c | 2 +- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/jdk/src/share/bin/java.c b/jdk/src/share/bin/java.c index 73c532676b3..b72fa0e6d26 100644 --- a/jdk/src/share/bin/java.c +++ b/jdk/src/share/bin/java.c @@ -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 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */ } \ } 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 @@ LoadMainClass(JNIEnv *env, int mode, char *name) "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 @@ ShowSettings(JNIEnv *env, char *optString) 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 @@ PrintUsage(JNIEnv* env, jboolean doXUsage) 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; iNewStringUTF(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; iNewStringUTF(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 @@ PrintUsage(JNIEnv* env, jboolean doXUsage) 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*/ diff --git a/jdk/src/windows/bin/java_md.c b/jdk/src/windows/bin/java_md.c index d08f2bf9bbe..c6a525f101d 100644 --- a/jdk/src/windows/bin/java_md.c +++ b/jdk/src/windows/bin/java_md.c @@ -1475,7 +1475,7 @@ CreateApplicationArgs(JNIEnv *env, char **strv, int argc) // 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]);