From a5dce40387dfb8102aa2408122e3f0fb6fe25a50 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Wed, 13 Jun 2018 11:24:12 +0200 Subject: [PATCH] Fix the way to get the JNI env in java wrapper to prevent crashes when some native threads stop. --- wrappers/java/jni.mustache | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wrappers/java/jni.mustache b/wrappers/java/jni.mustache index e226d5c68..549669a6f 100644 --- a/wrappers/java/jni.mustache +++ b/wrappers/java/jni.mustache @@ -283,9 +283,8 @@ static inline void handle_possible_java_exception(JNIEnv *env, jobject listener) {{#callbacks}} static {{return}} {{callbackName}}({{params}}) { - JNIEnv *env = 0; - jint jvmResult = jvm->AttachCurrentThread(&env,NULL); - if (jvmResult != 0) { + JNIEnv *env = ms_get_jni_env(); + if (!env) { ms_error("cannot attach VM"); return{{returnIfFail}}; }