Skip to content

Commit

Permalink
[fix](jdbc catalog) fix jdbc-connector coredump as get env return nul…
Browse files Browse the repository at this point in the history
…lptr (apache#32217)
  • Loading branch information
zy-kkk authored Mar 14, 2024
1 parent ee0a461 commit 60f97ab
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions be/src/util/jni-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,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();
Expand Down Expand Up @@ -407,7 +407,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");
Expand Down
11 changes: 9 additions & 2 deletions be/src/util/jni-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ class JniUtil {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct AggregateJavaUdafData {
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";
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/exec/vjdbc_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 60f97ab

Please sign in to comment.