Skip to content

Commit f506143

Browse files
committed
[CH-367] fix CH will continue to execute after JNI call fail
1 parent ea6d8dd commit f506143

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

utils/local-engine/jni/jni_common.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ jbyteArray stringTojbyteArray(JNIEnv* env, const std::string & str);
2626
if ((env)->ExceptionCheck())\
2727
{\
2828
LOG_ERROR(&Poco::Logger::get("local_engine"), "Enter java exception handle.");\
29-
auto throwable = (env)->ExceptionOccurred();\
30-
jclass exceptionClass = (env)->FindClass("java/lang/Exception"); \
31-
jmethodID getMessageMethod = (env)->GetMethodID(exceptionClass, "getMessage", "()Ljava/lang/String;"); \
32-
jstring message = static_cast<jstring>((env)->CallObjectMethod(throwable, getMessageMethod)); \
33-
const char *messageChars = (env)->GetStringUTFChars(message, NULL); \
34-
LOG_ERROR(&Poco::Logger::get("jni"), "exception:{}", messageChars); \
35-
(env)->ReleaseStringUTFChars(message, messageChars); \
36-
(env)->Throw(throwable);\
29+
auto excp = (env)->ExceptionOccurred();\
30+
(env)->ExceptionDescribe();\
31+
(env)->ExceptionClear();\
32+
jclass cls = (env)->GetObjectClass(excp); \
33+
jmethodID mid = env->GetMethodID(cls, "toString","()Ljava/lang/String;");\
34+
jstring jmsg = static_cast<jstring>((env)->CallObjectMethod(excp, mid));\
35+
const char *nmsg = (env)->GetStringUTFChars(jmsg, NULL);\
36+
std::string msg = std::string(nmsg);\
37+
env->ReleaseStringUTFChars(jmsg, nmsg);\
38+
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, msg);\
3739
}
3840

3941
template <typename ... Args>

0 commit comments

Comments
 (0)