Author: amiloslavskiy Date: Thu Oct 15 10:15:14 2020 New Revision: 1882521 URL: http://svn.apache.org/viewvc?rev=1882521&view=rev Log: JavaHL: Fix 'JNI call made without checking exceptions when required to'
Java JNI documentation says: The JNI functions that invoke a Java method return the result of the Java method. The programmer must call ExceptionOccurred() to check for possible exceptions that occurred during the execution of the Java method. These warnings are seen in JavaHL tests due to '-Xcheck:jni' option. [in subversion/bindings/javahl] * native/JNIUtil.cpp Properly check for exceptions after every 'CallObjectMethod()'. In case of exception, return NULL, which is valid, because the callers are prepared for it: * exception_to_cstring() JNIUtil::thrownExceptionToCString() ClientContext::resolve() Passes result to 'svn_error_create()' Documented to be able to deal with NULL. * JNIUtil::checkJavaException() Explicitly handles returned NULL. Modified: subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp Modified: subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp URL: http://svn.apache.org/viewvc/subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1882521&r1=1882520&r2=1882521&view=diff ============================================================================== --- subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp (original) +++ subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp Thu Oct 15 10:15:14 2020 @@ -779,9 +779,14 @@ const char* known_exception_to_cstring(a { jmethodID mid = env->GetMethodID(cls, "getClass", "()Ljava/lang/Class;"); jobject clsobj = env->CallObjectMethod(t, mid); + if (JNIUtil::isJavaExceptionThrown()) + return NULL; + jclass basecls = env->GetObjectClass(clsobj); mid = env->GetMethodID(basecls, "getName", "()Ljava/lang/String;"); jclass_name = (jstring) env->CallObjectMethod(clsobj, mid); + if (JNIUtil::isJavaExceptionThrown()) + return NULL; } jstring jmessage; @@ -789,6 +794,8 @@ const char* known_exception_to_cstring(a jmethodID mid = env->GetMethodID(cls, "getMessage", "()Ljava/lang/String;"); jmessage = (jstring) env->CallObjectMethod(t, mid); + if (JNIUtil::isJavaExceptionThrown()) + return NULL; } JNIStringHolder class_name(jclass_name);