Skip to content

Commit 38b39c1

Browse files
committed
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
1 parent 37bce97 commit 38b39c1

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Sources/JavaKit/Exceptions/ExceptionHandling.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ extension JNIEnvironment {
2020

2121
// Check whether a Java exception occurred.
2222
if let exception = interface.ExceptionOccurred(self) {
23-
let throwable = Throwable(javaThis: exception, environment: self)
2423
interface.ExceptionClear(self)
25-
throw throwable
24+
throw Throwable(javaThis: exception, environment: self)
2625
}
2726

2827
return result

0 commit comments

Comments
 (0)