Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-5327

Handle return value and exception of JNI GetStringUTFChars()

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • Impala 2.5.0, Impala 2.6.0, Impala 2.7.0, Impala 2.8.0
    • Impala 2.10.0
    • Backend

    Description

      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:

      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());
      }
      

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            tianyiwang Tianyi Wang
            alex.behm Alexander Behm
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Issue deployment