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

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


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

commit bbdce3eb5ee50c4d97b6a476d85459c88ba3c76b
Author: zy-kkk <zhongy...@gmail.com>
AuthorDate: Thu Mar 14 16:04:06 2024 +0800

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

diff --git a/be/src/util/jni-util.cpp b/be/src/util/jni-util.cpp
index 15344a22a8d..c626ee021ed 100644
--- a/be/src/util/jni-util.cpp
+++ b/be/src/util/jni-util.cpp
@@ -140,7 +140,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();
@@ -406,7 +406,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 317ba48d3d1..ca305c32bf1 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/aggregate_functions/aggregate_function_java_udaf.h 
b/be/src/vec/aggregate_functions/aggregate_function_java_udaf.h
index 4ef64aae558..7a367623eaf 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_java_udaf.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_java_udaf.h
@@ -60,7 +60,7 @@ public:
     AggregateJavaUdafData(int64_t num_args) { argument_size = num_args; }
 
     ~AggregateJavaUdafData() {
-        JNIEnv* env;
+        JNIEnv* env = nullptr;
         if (!JniUtil::GetJNIEnv(&env).ok()) {
             LOG(WARNING) << "Failed to get JNIEnv";
         }
diff --git a/be/src/vec/exec/vjdbc_connector.cpp 
b/be/src/vec/exec/vjdbc_connector.cpp
index 4020278e84d..318651ea885 100644
--- a/be/src/vec/exec/vjdbc_connector.cpp
+++ b/be/src/vec/exec/vjdbc_connector.cpp
@@ -83,7 +83,7 @@ Status JdbcConnector::close(Status /*unused*/) {
     if (_is_in_transaction) {
         RETURN_IF_ERROR(abort_trans());
     }
-    JNIEnv* env;
+    JNIEnv* env = nullptr;
     RETURN_IF_ERROR(JniUtil::GetJNIEnv(&env));
     env->DeleteGlobalRef(_executor_factory_clazz);
     env->DeleteGlobalRef(_executor_clazz);


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

Reply via email to