# HG changeset patch # User ksrini # Date 1389734351 28800 # Node ID 877c94f9476b98ed2b63c54ffe1330ea35943dbb # Parent a32375f9a4b5bc68f03c86e6cbcfeb35ce5ed485 8031494: [launcher] java launcher should check for JNI Pending exceptions. Reviewed-by: alanb, chegar, mchung diff -r a32375f9a4b5 -r 877c94f9476b jdk/src/share/bin/java.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; 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 @@ 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 -r a32375f9a4b5 -r 877c94f9476b jdk/src/windows/bin/java_md.c --- 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]);