diff options
author | Sven Gothel <[email protected]> | 2022-11-26 18:25:18 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-11-26 18:25:18 +0100 |
commit | 571a84e1dabca7d4a4fbba198b36badaff36f14d (patch) | |
tree | 2422d5c570fd671f32b6306456d4b8cf5150bdfe /java_jni/jni | |
parent | e8e1c301fc55af2429d9a14f815562b559904a00 (diff) |
clang-tidy: jni_mem.cxx: Catch potential '*jni_env' exception on noexcept methods
Diffstat (limited to 'java_jni/jni')
-rw-r--r-- | java_jni/jni/jni_mem.cxx | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/java_jni/jni/jni_mem.cxx b/java_jni/jni/jni_mem.cxx index 024a8bc..e2ee14b 100644 --- a/java_jni/jni/jni_mem.cxx +++ b/java_jni/jni/jni_mem.cxx @@ -214,9 +214,16 @@ JNIGlobalRef::~JNIGlobalRef() noexcept { } jobjectRefType JNIGlobalRef::getObjectRefType() const noexcept { - JNIEnv * env = *jni_env; - std::unique_lock<std::mutex> lock(mtx); - return env->GetObjectRefType(object); + try { + JNIEnv * env = *jni_env; + std::unique_lock<std::mutex> lock(mtx); + return env->GetObjectRefType(object); + } catch (const jau::ExceptionBase &e) { + ERR_PRINT("%s", e.message().c_str()); + } catch (...) { + ERR_PRINT("Unknown exception"); + } + return jobjectRefType::JNIInvalidRefType; } jobject JNIGlobalRef::operator*() noexcept { @@ -235,12 +242,19 @@ bool JNIGlobalRef::operator==(const JNIGlobalRef& rhs) const noexcept { DBG_JNI_PRINT("JNIGlobalRef::== true: %p == %p (ptr)", object, rhs.object); return true; } - JNIEnv * env = *jni_env; - std::unique_lock<std::mutex> lockThis(mtx, std::defer_lock); // utilize std::lock(r, w), allowing mixed order w/o deadlock - std::unique_lock<std::mutex> lockThat(rhs.mtx, std::defer_lock); // otherwise RAII-style relinquish via destructor - std::lock(lockThis, lockThat); + bool res = false; + try { + JNIEnv * env = *jni_env; + std::unique_lock<std::mutex> lockThis(mtx, std::defer_lock); // utilize std::lock(r, w), allowing mixed order w/o deadlock + std::unique_lock<std::mutex> lockThat(rhs.mtx, std::defer_lock); // otherwise RAII-style relinquish via destructor + std::lock(lockThis, lockThat); - bool res = JNI_TRUE == env->IsSameObject(object, rhs.object); - DBG_JNI_PRINT("JNIGlobalRef::== %d: %p == %p (IsSameObject)", res, object, rhs.object); + res = JNI_TRUE == env->IsSameObject(object, rhs.object); + DBG_JNI_PRINT("JNIGlobalRef::== %d: %p == %p (IsSameObject)", res, object, rhs.object); + } catch (const jau::ExceptionBase &e) { + ERR_PRINT("%s", e.message().c_str()); + } catch (...) { + ERR_PRINT("Unknown exception"); + } return res; } |