Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

If a Java call triggers an exception, clear the exception so JNI can continue operation #54

Open
paulproteus opened this issue Dec 8, 2020 · 0 comments

Comments

@paulproteus
Copy link
Contributor

Describe the bug
If there's a Java exception, we need to at least clear the exception so JNI knows we're aware of it.

When do we so, it is smart to print its stacktrace or otherwise do something useful for debugging. It might be sensible to raise a Python exception.

To Reproduce
Steps to reproduce the behavior:

  • Run some Python code that triggers an unhandled Java exception
  • Immediately after that, run some more Python code that does operations against JNI

Expected behavior

Clear the JNI exception state. Additionally, perhaps see a Java stacktrace or other information about what caused the exception, perhaps in the form of a Python exception.

Actual behavior

On Android, the process gets killed, and this gets logged. Note the text about a "pending exception."

I/DEBUG   ( 1143): signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
I/DEBUG   ( 1143): Abort message: 'art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception 'java.lang.ClassNotFoundException' thrown in unknown throw location'
I/DEBUG   ( 1143):     eax 00000000  ebx 00000a47  ecx 00000a47  edx 00000006
I/DEBUG   ( 1143):     esi b77cfc48  edi 0000000b
I/DEBUG   ( 1143):     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000007  xss 0000007b
I/DEBUG   ( 1143):     eip b755d2e6  ebp 00000a47  esp bf96dcd0  flags 00000286

Additional context

beeware/briefcase#538

See e.g. https://www.developer.com/java/data/exception-handling-in-jni.html and https://docs.oracle.com/en/java/javase/13/docs/specs/jni/functions.html#exceptioncheck to check for these exceptions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants