diff --git a/td/tl/tl_jni_object.cpp b/td/tl/tl_jni_object.cpp index 640635c32..169e0dd3b 100644 --- a/td/tl/tl_jni_object.cpp +++ b/td/tl/tl_jni_object.cpp @@ -79,7 +79,7 @@ void register_native_method(JNIEnv *env, jclass clazz, std::string name, std::st std::unique_ptr get_jni_env(JavaVM *java_vm, jint jni_version) { JNIEnv *env = nullptr; - if (java_vm->GetEnv(reinterpret_cast(&env), jni_version) == JNI_EDETACHED) { + if (java_vm->GetEnv(reinterpret_cast(&env), jni_version) == JNI_EDETACHED && env != nullptr) { #ifdef JDK1_2 // if not Android JNI auto p_env = reinterpret_cast(&env); #else