From 3dfa925333f0585e360a77dee6c3ae9e85a66507 Mon Sep 17 00:00:00 2001 From: Dan Heidinga Date: Wed, 4 Jul 2018 17:53:05 +0000 Subject: [PATCH] Add missing JNI exception check Adjust formatting to be consistent and update comments to indicate that an exception will always be pending at that point so no explicit action is required. Signed-off-by: Dan Heidinga --- runtime/jcl/common/dump.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/runtime/jcl/common/dump.c b/runtime/jcl/common/dump.c index 2b228e0c3f0..0ed54753aa0 100644 --- a/runtime/jcl/common/dump.c +++ b/runtime/jcl/common/dump.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1998, 2016 IBM Corp. and others + * Copyright (c) 1998, 2018 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -305,20 +305,22 @@ Java_com_ibm_jvm_Dump_setDumpOptionsImpl (JNIEnv *env, jclass clazz, jstring jop memset(optsBuffer, 0, optsLength+1); (*env)->GetStringUTFRegion(env, jopts, 0, optsLength, optsBuffer); + if (!(*env)->ExceptionCheck(env)) { - /* Pass option to the dump facade */ - result = vm->j9rasDumpFunctions->setDumpOption(vm, optsBuffer); + /* Pass option to the dump facade */ + result = vm->j9rasDumpFunctions->setDumpOption(vm, optsBuffer); - /* Map back to exception */ - if (OMR_ERROR_NONE != result) { - raiseExceptionFor(env, result); - } + /* Map back to exception */ + if (OMR_ERROR_NONE != result) { + raiseExceptionFor(env, result); + } + } } else { jclass exceptionClass = (*env)->FindClass(env, "java/lang/OutOfMemoryError"); if (exceptionClass != NULL) { (*env)->ThrowNew(env, exceptionClass, "Out of memory setting dump options"); } - /* Just return if we can't load the exception class. */ + /* Just return if we can't load the exception class as an exception will be pending. */ } if( optsBuffer != NULL ) { @@ -327,7 +329,7 @@ Java_com_ibm_jvm_Dump_setDumpOptionsImpl (JNIEnv *env, jclass clazz, jstring jop #else jclass exceptionClass = (*env)->FindClass(env, "java/lang/RuntimeException"); if (exceptionClass == 0) { - /* Just return if we can't load the exception class. */ + /* Just return if we can't load the exception class as an exception will be pending. */ return JNI_ERR; } (*env)->ThrowNew(env, exceptionClass, "Dumps not supported in this configuration");