Alexander Behm created IMPALA-5327:
--------------------------------------

             Summary: 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


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.3.15#6346)

Reply via email to