Skip to content

Commit

Permalink
[CH-367] fix CH will continue to execute after JNI call fail
Browse files Browse the repository at this point in the history
  • Loading branch information
shuai-xu committed Apr 13, 2023
1 parent ea6d8dd commit f506143
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions utils/local-engine/jni/jni_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ jbyteArray stringTojbyteArray(JNIEnv* env, const std::string & str);
if ((env)->ExceptionCheck())\
{\
LOG_ERROR(&Poco::Logger::get("local_engine"), "Enter java exception handle.");\
auto throwable = (env)->ExceptionOccurred();\
jclass exceptionClass = (env)->FindClass("java/lang/Exception"); \
jmethodID getMessageMethod = (env)->GetMethodID(exceptionClass, "getMessage", "()Ljava/lang/String;"); \
jstring message = static_cast<jstring>((env)->CallObjectMethod(throwable, getMessageMethod)); \
const char *messageChars = (env)->GetStringUTFChars(message, NULL); \
LOG_ERROR(&Poco::Logger::get("jni"), "exception:{}", messageChars); \
(env)->ReleaseStringUTFChars(message, messageChars); \
(env)->Throw(throwable);\
auto excp = (env)->ExceptionOccurred();\
(env)->ExceptionDescribe();\
(env)->ExceptionClear();\
jclass cls = (env)->GetObjectClass(excp); \
jmethodID mid = env->GetMethodID(cls, "toString","()Ljava/lang/String;");\
jstring jmsg = static_cast<jstring>((env)->CallObjectMethod(excp, mid));\
const char *nmsg = (env)->GetStringUTFChars(jmsg, NULL);\
std::string msg = std::string(nmsg);\
env->ReleaseStringUTFChars(jmsg, nmsg);\
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, msg);\
}

template <typename ... Args>
Expand Down

0 comments on commit f506143

Please sign in to comment.