From cdb9c38ee062292c05f1e113b8b8702e199160fe Mon Sep 17 00:00:00 2001 From: Hui Xu Date: Thu, 30 May 2024 18:16:43 +0800 Subject: [PATCH] external/jnipp: Check and re-assign JNIEnv Fixes a crash when resumed from launcher. Part-of: --- doc/changes/misc_fixes/mr.2200.md | 5 ++++- src/external/jnipp/jnipp.cpp | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/changes/misc_fixes/mr.2200.md b/doc/changes/misc_fixes/mr.2200.md index fb8b59bf8..679339bf5 100644 --- a/doc/changes/misc_fixes/mr.2200.md +++ b/doc/changes/misc_fixes/mr.2200.md @@ -1 +1,4 @@ -jnipp: Update to fix issues including CTS crashes. +--- +- mr.2226 +--- +jnipp: Update/patch to fix issues, including crashes. diff --git a/src/external/jnipp/jnipp.cpp b/src/external/jnipp/jnipp.cpp index 930cbebb4..15838a68b 100644 --- a/src/external/jnipp/jnipp.cpp +++ b/src/external/jnipp/jnipp.cpp @@ -156,11 +156,22 @@ namespace jni #endif // _WIN32 + static bool isEnvChanged(JavaVM* vm, ScopedEnv& threadLocalEnv) { + if (vm == nullptr) + { + return false; + } + JNIEnv *curEnv = nullptr; + getEnv(vm, &curEnv); + return curEnv != threadLocalEnv.get(); + } + + JNIEnv* env() { static thread_local ScopedEnv env; - if (env.get() != nullptr && !isAttached(javaVm)) + if (env.get() != nullptr && (!isAttached(javaVm) || isEnvChanged(javaVm, env))) { // we got detached, so clear it. // will be re-populated from static javaVm below.