From 38b39c157fb7be6b93c2b0600b74a3f4ff69fffd Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Fri, 1 Nov 2024 10:36:04 +1100 Subject: [PATCH] JavaKit: clear exception before initializing Throwable Initializing Throwable with an exception calls the JNI method NewGlobalRef, which on Android cannot be called while an exception is pending. [1] Clear the exception first before initializing the Throwable. [1] https://developer.android.com/training/articles/perf-jni.html#exceptions_1 --- Sources/JavaKit/Exceptions/ExceptionHandling.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/JavaKit/Exceptions/ExceptionHandling.swift b/Sources/JavaKit/Exceptions/ExceptionHandling.swift index efd98e94..cf063d0a 100644 --- a/Sources/JavaKit/Exceptions/ExceptionHandling.swift +++ b/Sources/JavaKit/Exceptions/ExceptionHandling.swift @@ -20,9 +20,8 @@ extension JNIEnvironment { // Check whether a Java exception occurred. if let exception = interface.ExceptionOccurred(self) { - let throwable = Throwable(javaThis: exception, environment: self) interface.ExceptionClear(self) - throw throwable + throw Throwable(javaThis: exception, environment: self) } return result