Skip to content

Commit

Permalink
Merge pull request #2322 from DanHeidinga/djh/exceptioncheck
Browse files Browse the repository at this point in the history
Add missing JNI exception check
  • Loading branch information
keithc-ca authored Jul 9, 2018
2 parents 8034324 + 3dfa925 commit 67ad9d0
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions runtime/jcl/common/dump.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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");
Expand Down

0 comments on commit 67ad9d0

Please sign in to comment.