This is an automated email from the ASF dual-hosted git repository.

zykkk pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 131fa126f7a [fix](jdbc catalog) fix jdbc-connector coredump as get env 
return nullptr (#32217) (#32304)
131fa126f7a is described below

commit 131fa126f7a69a5a40d4803edf04e6b74b6b1e55
Author: zy-kkk <zhongy...@gmail.com>
AuthorDate: Sun Mar 17 17:51:54 2024 +0800

    [fix](jdbc catalog) fix jdbc-connector coredump as get env return nullptr 
(#32217) (#32304)
---
 be/src/util/jni-util.cpp            |  4 ++--
 be/src/util/jni-util.h              | 11 +++++++++--
 be/src/vec/exec/vjdbc_connector.cpp |  2 +-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/be/src/util/jni-util.cpp b/be/src/util/jni-util.cpp
index c1ea26798b9..f48ec9fbf46 100644
--- a/be/src/util/jni-util.cpp
+++ b/be/src/util/jni-util.cpp
@@ -123,7 +123,7 @@ const std::string GetDorisJNIClasspathOption() {
             jvm_options[i] = {const_cast<char*>(options[i].c_str()), nullptr};
         }
 
-        JNIEnv* env;
+        JNIEnv* env = nullptr;
         JavaVMInitArgs vm_args;
         vm_args.version = JNI_VERSION_1_8;
         vm_args.options = jvm_options.get();
@@ -389,7 +389,7 @@ Status JniUtil::Init() {
     RETURN_IF_ERROR(LibJVMLoader::instance().load());
 
     // Get the JNIEnv* corresponding to current thread.
-    JNIEnv* env;
+    JNIEnv* env = nullptr;
     RETURN_IF_ERROR(JniUtil::GetJNIEnv(&env));
 
     if (env == NULL) return Status::InternalError("Failed to get/create JVM");
diff --git a/be/src/util/jni-util.h b/be/src/util/jni-util.h
index faa79c91330..d2a30411b05 100644
--- a/be/src/util/jni-util.h
+++ b/be/src/util/jni-util.h
@@ -52,9 +52,16 @@ public:
     static Status GetJNIEnv(JNIEnv** env) {
         if (tls_env_) {
             *env = tls_env_;
-            return Status::OK();
+        } else {
+            Status status = GetJNIEnvSlowPath(env);
+            if (!status.ok()) {
+                return status;
+            }
         }
-        return GetJNIEnvSlowPath(env);
+        if (*env == nullptr) {
+            return Status::RuntimeError("Failed to get JNIEnv: it is 
nullptr.");
+        }
+        return Status::OK();
     }
 
     static Status GetGlobalClassRef(JNIEnv* env, const char* class_str,
diff --git a/be/src/vec/exec/vjdbc_connector.cpp 
b/be/src/vec/exec/vjdbc_connector.cpp
index 666a06531d2..23602e52d6d 100644
--- a/be/src/vec/exec/vjdbc_connector.cpp
+++ b/be/src/vec/exec/vjdbc_connector.cpp
@@ -98,7 +98,7 @@ Status JdbcConnector::close() {
     if (_is_in_transaction) {
         RETURN_IF_ERROR(abort_trans());
     }
-    JNIEnv* env;
+    JNIEnv* env = nullptr;
     RETURN_IF_ERROR(JniUtil::GetJNIEnv(&env));
     env->DeleteGlobalRef(_executor_clazz);
     DELETE_BASIC_JAVA_CLAZZ_REF(object)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to