提交 9cbb51dc 编写于 作者: R rriggs

8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions

Summary: Check for pending exceptions
Reviewed-by: alanb, chegar
上级 1c5ae948
...@@ -683,10 +683,14 @@ initializeEncoding(JNIEnv *env) ...@@ -683,10 +683,14 @@ initializeEncoding(JNIEnv *env)
{ {
jstring propname = 0; jstring propname = 0;
jstring enc = 0; jstring enc = 0;
jclass strClazz = NULL;
if ((*env)->EnsureLocalCapacity(env, 3) < 0) if ((*env)->EnsureLocalCapacity(env, 3) < 0)
return; return;
strClazz = JNU_ClassString(env);
CHECK_NULL(strClazz);
propname = (*env)->NewStringUTF(env, "sun.jnu.encoding"); propname = (*env)->NewStringUTF(env, "sun.jnu.encoding");
if (propname) { if (propname) {
jboolean exc; jboolean exc;
...@@ -740,9 +744,10 @@ initializeEncoding(JNIEnv *env) ...@@ -740,9 +744,10 @@ initializeEncoding(JNIEnv *env)
(*env)->DeleteLocalRef(env, enc); (*env)->DeleteLocalRef(env, enc);
/* Initialize method-id cache */ /* Initialize method-id cache */
String_getBytes_ID = (*env)->GetMethodID(env, JNU_ClassString(env), String_getBytes_ID = (*env)->GetMethodID(env, strClazz,
"getBytes", "(Ljava/lang/String;)[B"); "getBytes", "(Ljava/lang/String;)[B");
String_init_ID = (*env)->GetMethodID(env, JNU_ClassString(env), CHECK_NULL(String_getBytes_ID);
String_init_ID = (*env)->GetMethodID(env, strClazz,
"<init>", "([BLjava/lang/String;)V"); "<init>", "([BLjava/lang/String;)V");
} }
...@@ -777,8 +782,10 @@ JNU_NewStringPlatform(JNIEnv *env, const char *str) ...@@ -777,8 +782,10 @@ JNU_NewStringPlatform(JNIEnv *env, const char *str)
jbyteArray hab = 0; jbyteArray hab = 0;
int len; int len;
if (fastEncoding == NO_ENCODING_YET) if (fastEncoding == NO_ENCODING_YET) {
initializeEncoding(env); initializeEncoding(env);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
}
if ((fastEncoding == FAST_8859_1) || (fastEncoding == NO_ENCODING_YET)) if ((fastEncoding == FAST_8859_1) || (fastEncoding == NO_ENCODING_YET))
return newString8859_1(env, str); return newString8859_1(env, str);
...@@ -793,9 +800,11 @@ JNU_NewStringPlatform(JNIEnv *env, const char *str) ...@@ -793,9 +800,11 @@ JNU_NewStringPlatform(JNIEnv *env, const char *str)
len = (int)strlen(str); len = (int)strlen(str);
hab = (*env)->NewByteArray(env, len); hab = (*env)->NewByteArray(env, len);
if (hab != 0) { if (hab != 0) {
jclass strClazz = JNU_ClassString(env);
CHECK_NULL_RETURN(strClazz, 0);
(*env)->SetByteArrayRegion(env, hab, 0, len, (jbyte *)str); (*env)->SetByteArrayRegion(env, hab, 0, len, (jbyte *)str);
if (jnuEncodingSupported(env)) { if (jnuEncodingSupported(env)) {
result = (*env)->NewObject(env, JNU_ClassString(env), result = (*env)->NewObject(env, strClazz,
String_init_ID, hab, jnuEncoding); String_init_ID, hab, jnuEncoding);
} else { } else {
/*If the encoding specified in sun.jnu.encoding is not endorsed /*If the encoding specified in sun.jnu.encoding is not endorsed
...@@ -804,9 +813,11 @@ JNU_NewStringPlatform(JNIEnv *env, const char *str) ...@@ -804,9 +813,11 @@ JNU_NewStringPlatform(JNIEnv *env, const char *str)
StringCoding class will pickup the iso-8859-1 as the fallback StringCoding class will pickup the iso-8859-1 as the fallback
converter for us. converter for us.
*/ */
jmethodID mid = (*env)->GetMethodID(env, JNU_ClassString(env), jmethodID mid = (*env)->GetMethodID(env, strClazz,
"<init>", "([B)V"); "<init>", "([B)V");
result = (*env)->NewObject(env, JNU_ClassString(env), mid, hab); if (mid != NULL) {
result = (*env)->NewObject(env, strClazz, mid, hab);
}
} }
(*env)->DeleteLocalRef(env, hab); (*env)->DeleteLocalRef(env, hab);
return result; return result;
...@@ -832,8 +843,10 @@ JNU_GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy) ...@@ -832,8 +843,10 @@ JNU_GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy)
if (isCopy) if (isCopy)
*isCopy = JNI_TRUE; *isCopy = JNI_TRUE;
if (fastEncoding == NO_ENCODING_YET) if (fastEncoding == NO_ENCODING_YET) {
initializeEncoding(env); initializeEncoding(env);
JNU_CHECK_EXCEPTION_RETURN(env, 0);
}
if ((fastEncoding == FAST_8859_1) || (fastEncoding == NO_ENCODING_YET)) if ((fastEncoding == FAST_8859_1) || (fastEncoding == NO_ENCODING_YET))
return getString8859_1Chars(env, jstr); return getString8859_1Chars(env, jstr);
...@@ -848,9 +861,14 @@ JNU_GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy) ...@@ -848,9 +861,14 @@ JNU_GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy)
if (jnuEncodingSupported(env)) { if (jnuEncodingSupported(env)) {
hab = (*env)->CallObjectMethod(env, jstr, String_getBytes_ID, jnuEncoding); hab = (*env)->CallObjectMethod(env, jstr, String_getBytes_ID, jnuEncoding);
} else { } else {
jmethodID mid = (*env)->GetMethodID(env, JNU_ClassString(env), jmethodID mid;
"getBytes", "()[B"); jclass strClazz = JNU_ClassString(env);
hab = (*env)->CallObjectMethod(env, jstr, mid); CHECK_NULL_RETURN(strClazz, 0);
mid = (*env)->GetMethodID(env, strClazz,
"getBytes", "()[B");
if (mid != NULL) {
hab = (*env)->CallObjectMethod(env, jstr, mid);
}
} }
if (!(*env)->ExceptionCheck(env)) { if (!(*env)->ExceptionCheck(env)) {
...@@ -899,6 +917,7 @@ JNU_ClassString(JNIEnv *env) ...@@ -899,6 +917,7 @@ JNU_ClassString(JNIEnv *env)
if ((*env)->EnsureLocalCapacity(env, 1) < 0) if ((*env)->EnsureLocalCapacity(env, 1) < 0)
return 0; return 0;
c = (*env)->FindClass(env, "java/lang/String"); c = (*env)->FindClass(env, "java/lang/String");
CHECK_NULL_RETURN(c, NULL);
cls = (*env)->NewGlobalRef(env, c); cls = (*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c); (*env)->DeleteLocalRef(env, c);
} }
...@@ -914,6 +933,7 @@ JNU_ClassClass(JNIEnv *env) ...@@ -914,6 +933,7 @@ JNU_ClassClass(JNIEnv *env)
if ((*env)->EnsureLocalCapacity(env, 1) < 0) if ((*env)->EnsureLocalCapacity(env, 1) < 0)
return 0; return 0;
c = (*env)->FindClass(env, "java/lang/Class"); c = (*env)->FindClass(env, "java/lang/Class");
CHECK_NULL_RETURN(c, NULL);
cls = (*env)->NewGlobalRef(env, c); cls = (*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c); (*env)->DeleteLocalRef(env, c);
} }
...@@ -929,6 +949,7 @@ JNU_ClassObject(JNIEnv *env) ...@@ -929,6 +949,7 @@ JNU_ClassObject(JNIEnv *env)
if ((*env)->EnsureLocalCapacity(env, 1) < 0) if ((*env)->EnsureLocalCapacity(env, 1) < 0)
return 0; return 0;
c = (*env)->FindClass(env, "java/lang/Object"); c = (*env)->FindClass(env, "java/lang/Object");
CHECK_NULL_RETURN(c, NULL);
cls = (*env)->NewGlobalRef(env, c); cls = (*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c); (*env)->DeleteLocalRef(env, c);
} }
...@@ -944,6 +965,7 @@ JNU_ClassThrowable(JNIEnv *env) ...@@ -944,6 +965,7 @@ JNU_ClassThrowable(JNIEnv *env)
if ((*env)->EnsureLocalCapacity(env, 1) < 0) if ((*env)->EnsureLocalCapacity(env, 1) < 0)
return 0; return 0;
c = (*env)->FindClass(env, "java/lang/Throwable"); c = (*env)->FindClass(env, "java/lang/Throwable");
CHECK_NULL_RETURN(c, NULL);
cls = (*env)->NewGlobalRef(env, c); cls = (*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c); (*env)->DeleteLocalRef(env, c);
} }
...@@ -993,8 +1015,11 @@ JNU_Equals(JNIEnv *env, jobject object1, jobject object2) ...@@ -993,8 +1015,11 @@ JNU_Equals(JNIEnv *env, jobject object1, jobject object2)
{ {
static jmethodID mid = NULL; static jmethodID mid = NULL;
if (mid == NULL) { if (mid == NULL) {
mid = (*env)->GetMethodID(env, JNU_ClassObject(env), "equals", jclass objClazz = JNU_ClassObject(env);
CHECK_NULL_RETURN(objClazz, JNI_FALSE);
mid = (*env)->GetMethodID(env, objClazz, "equals",
"(Ljava/lang/Object;)Z"); "(Ljava/lang/Object;)Z");
CHECK_NULL_RETURN(mid, JNI_FALSE);
} }
return (*env)->CallBooleanMethod(env, object1, mid, object2); return (*env)->CallBooleanMethod(env, object1, mid, object2);
} }
...@@ -1096,7 +1121,9 @@ JNU_PrintClass(JNIEnv *env, char* hdr, jobject object) ...@@ -1096,7 +1121,9 @@ JNU_PrintClass(JNIEnv *env, char* hdr, jobject object)
} else { } else {
jclass cls = (*env)->GetObjectClass(env, object); jclass cls = (*env)->GetObjectClass(env, object);
jstring clsName = JNU_ToString(env, cls); jstring clsName = JNU_ToString(env, cls);
JNU_PrintString(env, hdr, clsName); if (clsName == NULL) {
JNU_PrintString(env, hdr, clsName);
}
(*env)->DeleteLocalRef(env, cls); (*env)->DeleteLocalRef(env, cls);
(*env)->DeleteLocalRef(env, clsName); (*env)->DeleteLocalRef(env, clsName);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册