aboutsummaryrefslogtreecommitdiffstats
path: root/java_jni/jni
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-05-09 01:16:57 +0200
committerSven Gothel <[email protected]>2022-05-09 01:16:57 +0200
commitf61e1835c9a7e547342393f7a77098b7bfd68d22 (patch)
treebe9076fa9119c074a3e4d5e72a1abe8928688c07 /java_jni/jni
parent236d681664f2309a99c72dc8598c516adf5189ff (diff)
~JNIGlobalRef(): Only show brief error message if root_environment::is_terminating() at exit: Reason is that we can't attach to JVM after shutdown initiated.
Diffstat (limited to 'java_jni/jni')
-rw-r--r--java_jni/jni/jni_mem.cxx31
1 files changed, 24 insertions, 7 deletions
diff --git a/java_jni/jni/jni_mem.cxx b/java_jni/jni/jni_mem.cxx
index dbbc38c..3e72fc1 100644
--- a/java_jni/jni/jni_mem.cxx
+++ b/java_jni/jni/jni_mem.cxx
@@ -69,11 +69,11 @@ void JNIEnvContainer::attach() {
if( JNI_EDETACHED == envRes ) {
envRes = vm->AttachCurrentThreadAsDaemon((void**) &newEnv, NULL);
if( JNI_OK != envRes ) {
- throw jau::RuntimeException("Attach to VM failed", E_FILE_LINE);
+ throw jau::RuntimeException("Attach to VM failed, error "+std::to_string(envRes), E_FILE_LINE);
}
env = newEnv;
} else if( JNI_OK != envRes ) {
- throw jau::RuntimeException("GetEnv of VM failed", E_FILE_LINE);
+ throw jau::RuntimeException("GetEnv of VM failed, error "+std::to_string(envRes), E_FILE_LINE);
}
if (env==NULL) {
throw jau::RuntimeException("GetEnv of VM is NULL", E_FILE_LINE);
@@ -175,10 +175,7 @@ JNIGlobalRef& JNIGlobalRef::operator=(JNIGlobalRef &&o) noexcept {
JNIGlobalRef::~JNIGlobalRef() noexcept {
try {
- JNIEnv * env = *jni_env;
- if( nullptr == env ) {
- ABORT("JNIGlobalRef::dtor null JNIEnv");
- }
+ JNIEnv * env = *jni_env; // exception if null
std::unique_lock<std::mutex> lock(mtx);
DBG_JNI_PRINT("JNIGlobalRef::dtor %p", object);
if( nullptr != object ) {
@@ -191,8 +188,28 @@ JNIGlobalRef::~JNIGlobalRef() noexcept {
}
object = nullptr;
}
+ } catch (jau::ExceptionBase &e0) {
+ if( root_environment::is_terminating() ) {
+ if( jau::environment::get().debug ) {
+ fprintf(stderr, "JNIGlobalRef::dtor: Caught at exit %s\n", e0.what());
+ } else {
+ // Be brief @ exit, as its expected at JVM shutdown
+ fprintf(stderr, "JNIGlobalRef::dtor: Caught at exit %s\n", e0.message().c_str());
+ }
+ } else {
+ fprintf(stderr, "JNIGlobalRef::dtor: Caught %s\n", e0.what());
+ }
} catch (std::exception &e) {
- fprintf(stderr, "JNIGlobalRef::dtor: Caught %s\n", e.what());
+ if( root_environment::is_terminating() ) {
+ if( jau::environment::get().debug ) {
+ fprintf(stderr, "JNIGlobalRef::dtor: Caught at exit %s\n", e.what());
+ } else {
+ // Be brief @ exit, as its expected at JVM shutdown
+ fprintf(stderr, "JNIGlobalRef::dtor: Caught at exit ...\n");
+ }
+ } else {
+ fprintf(stderr, "JNIGlobalRef::dtor: Caught %s\n", e.what());
+ }
}
}