Skip to content

Commit

Permalink
8310628: GcInfoBuilder.c missing JNI Exception checks
Browse files Browse the repository at this point in the history
Reviewed-by: mchung, dholmes
  • Loading branch information
kevinjwalls committed Jun 23, 2023
1 parent 556831d commit a9c0a0f
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/jdk.management/share/native/libmanagement_ext/GcInfoBuilder.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, 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
Expand Down Expand Up @@ -129,7 +129,9 @@ static void setLongValueAtObjectArray(JNIEnv *env, jobjectArray array,
static const char* class_name = "java/lang/Long";
static const char* signature = "(J)V";
jobject obj = JNU_NewObjectByName(env, class_name, signature, value);

if ((*env)->ExceptionCheck(env)) {
return;
}
(*env)->SetObjectArrayElement(env, array, index, obj);
}

Expand All @@ -138,7 +140,9 @@ static void setBooleanValueAtObjectArray(JNIEnv *env, jobjectArray array,
static const char* class_name = "java/lang/Boolean";
static const char* signature = "(Z)V";
jobject obj = JNU_NewObjectByName(env, class_name, signature, value);

if ((*env)->ExceptionCheck(env)) {
return;
}
(*env)->SetObjectArrayElement(env, array, index, obj);
}

Expand All @@ -147,7 +151,9 @@ static void setByteValueAtObjectArray(JNIEnv *env, jobjectArray array,
static const char* class_name = "java/lang/Byte";
static const char* signature = "(B)V";
jobject obj = JNU_NewObjectByName(env, class_name, signature, value);

if ((*env)->ExceptionCheck(env)) {
return;
}
(*env)->SetObjectArrayElement(env, array, index, obj);
}

Expand All @@ -156,7 +162,9 @@ static void setIntValueAtObjectArray(JNIEnv *env, jobjectArray array,
static const char* class_name = "java/lang/Integer";
static const char* signature = "(I)V";
jobject obj = JNU_NewObjectByName(env, class_name, signature, value);

if ((*env)->ExceptionCheck(env)) {
return;
}
(*env)->SetObjectArrayElement(env, array, index, obj);
}

Expand All @@ -165,7 +173,9 @@ static void setShortValueAtObjectArray(JNIEnv *env, jobjectArray array,
static const char* class_name = "java/lang/Short";
static const char* signature = "(S)V";
jobject obj = JNU_NewObjectByName(env, class_name, signature, value);

if ((*env)->ExceptionCheck(env)) {
return;
}
(*env)->SetObjectArrayElement(env, array, index, obj);
}

Expand All @@ -174,7 +184,9 @@ static void setDoubleValueAtObjectArray(JNIEnv *env, jobjectArray array,
static const char* class_name = "java/lang/Double";
static const char* signature = "(D)V";
jobject obj = JNU_NewObjectByName(env, class_name, signature, value);

if ((*env)->ExceptionCheck(env)) {
return;
}
(*env)->SetObjectArrayElement(env, array, index, obj);
}

Expand All @@ -183,7 +195,9 @@ static void setFloatValueAtObjectArray(JNIEnv *env, jobjectArray array,
static const char* class_name = "java/lang/Float";
static const char* signature = "(D)V";
jobject obj = JNU_NewObjectByName(env, class_name, signature, value);

if ((*env)->ExceptionCheck(env)) {
return;
}
(*env)->SetObjectArrayElement(env, array, index, obj);
}

Expand All @@ -192,7 +206,9 @@ static void setCharValueAtObjectArray(JNIEnv *env, jobjectArray array,
static const char* class_name = "java/lang/Character";
static const char* signature = "(C)V";
jobject obj = JNU_NewObjectByName(env, class_name, signature, value);

if ((*env)->ExceptionCheck(env)) {
return;
}
(*env)->SetObjectArrayElement(env, array, index, obj);
}

Expand Down Expand Up @@ -293,6 +309,10 @@ JNIEXPORT jobject JNICALL Java_com_sun_management_internal_GcInfoBuilder_getLast
if (nativeTypes != NULL) {
free(nativeTypes);
}
// Recognise possible Exception from the switch statement above:
if ((*env)->ExceptionCheck(env)) {
return NULL;
}

return JNU_NewObjectByName(env,
"com/sun/management/GcInfo",
Expand Down

1 comment on commit a9c0a0f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.