You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@impala.apache.org by "Tianyi Wang (JIRA)" <ji...@apache.org> on 2017/08/17 17:30:00 UTC
[jira] [Resolved] (IMPALA-5327) Handle return value and exception
of JNI GetStringUTFChars()
[ https://issues.apache.org/jira/browse/IMPALA-5327?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tianyi Wang resolved IMPALA-5327.
---------------------------------
Resolution: Fixed
Fix Version/s: Impala 2.10.0
IMPALA-5327: Handle return of JNI GetStringUTFChar
GetStringUTFChars may return NULL or throw exception and it is not
handled in two places. This patch checks the return value/exception,
logs if there is error and return error to the caller. A helper class
JniUtfCharGuard is added to jni-util.h/cc to manage the lifetime.
Change-Id: I47eed045f21c6ed3a8decf422ce8429fc66c4322
Reviewed-on: http://gerrit.cloudera.org:8080/7642
Reviewed-by: Tim Armstrong <ta...@cloudera.com>
Tested-by: Impala Public Jenkins
> Handle return value and exception of JNI GetStringUTFChars()
> ------------------------------------------------------------
>
> Key: IMPALA-5327
> URL: https://issues.apache.org/jira/browse/IMPALA-5327
> Project: IMPALA
> Issue Type: Bug
> Components: Backend
> Affects Versions: Impala 2.5.0, Impala 2.6.0, Impala 2.7.0, Impala 2.8.0
> Reporter: Alexander Behm
> Assignee: Tianyi Wang
> Priority: Critical
> Labels: crash, ramp-up
> Fix For: Impala 2.10.0
>
>
> Several places in the code do not handle JNI GetStringUTFChars() correctly.
> 1. GetStringUTFChars() returns NULL if there is insufficient memory
> 2. GetStringUTFChars() may set an exception in the JNI env. That exception must be checked and clearer before any other call to the JNI env.
> Here's an example of the poor handling from jni-util.cc:
> {code}
> Status JniUtil::GetJniExceptionMsg(JNIEnv* env, bool log_stack, const string& prefix) {
> jthrowable exc = (env)->ExceptionOccurred();
> if (exc == NULL) return Status::OK();
> env->ExceptionClear();
> DCHECK(throwable_to_string_id() != NULL);
> jstring msg = (jstring) env->CallStaticObjectMethod(jni_util_class(),
> throwable_to_string_id(), exc);
> jboolean is_copy;
> string error_msg =
> (reinterpret_cast<const char*>(env->GetStringUTFChars(msg, &is_copy)));
> if (log_stack) {
> jstring stack = (jstring) env->CallStaticObjectMethod(jni_util_class(),
> throwable_to_stack_trace_id(), exc);
> const char* c_stack =
> reinterpret_cast<const char*>(env->GetStringUTFChars(stack, &is_copy));
> VLOG(1) << string(c_stack);
> }
> env->ExceptionClear();
> env->DeleteLocalRef(exc);
> stringstream ss;
> ss << prefix << error_msg;
> return Status(ss.str());
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)