Skip to content

fix: turn every C++ exception of a JNI entry point into a Java one - #530

Merged
devopvoid merged 3 commits into
mainfrom
fix/jni-entry-guards
Nov 4, 2026
Merged

devopvoid merged 3 commits into
mainfrom
fix/jni-entry-guards

Conversation

@devopvoid

Copy link
Copy Markdown
Owner
  • jni::CallFromJava runs the body of a JNI entry point and hands any C++ exception to Java, since one crossing the JNI boundary ends the JVM. 104 entry points use it now. Those in the files of fix/dispose-edge-cases and of the classes it is related to follow in a separate change.
  • The jni-check job also runs on macOS arm64 and Windows x86_64.
  • Paths that only run with real devices check for exceptions too: a Java AudioSource that throws on the playout thread is reported and plays nothing for that pull, a negative result of it counts as 0 samples, and device objects whose constructor threw are not filled anymore.
  • The JNI helpers free the local class references they create, which would otherwise pile up on native threads.

GetFieldID on an object and the class name lookup of JavaContext left the
class of GetObjectClass behind. On a native thread attached for a callback,
nothing frees local references until the thread detaches. The class loader
no longer creates a global reference while an exception is pending.
The jni-check job also runs on macOS arm64 and Windows x86_64, whose device
modules, capturers and codecs reach Java on code paths of their own. Ahead of
that, the paths only real devices take check their JNI calls: an AudioSource
that throws on the playout thread is reported instead of leaving the
exception pending, and a device whose Java constructor threw is not filled in.
A C++ exception that reaches the VM ends the process. jni::CallFromJava runs
the body of an entry point and turns any into a Java exception, the way the
entry points with a try block of their own do. It now guards those that had
none, or that called a throwing helper before their try block.
@devopvoid
devopvoid merged commit 9e450ec into main Nov 4, 2026
24 of 25 checks passed
@devopvoid
devopvoid deleted the fix/jni-entry-guards branch November 4, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant