You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"For new JNI code validate that there is a check for an exception after all JNI calls that can raise an exception."
Current Neuropod JNI code doesn't have any "env‑>ExceptionCheck". Except a check, JNI code should clear it after all. Need to use some consistent approach for every JNI call that may throw exception.
Note, I looked at Tensorflow Java/JNI code and found that its JNI exception handling is not consistent, it only checks for env‑>ExceptionCheck and never clears it.
There are JVM flags dedicated for tracing and checking JNI code. Consider what JNI check options available in target JVM (‑Xcheck:jni). Note source/neuropod/bindings/java/java_build_defs.bzl already uses some settings for "bazel errorprone plugin" (for instance
"-Xep:ExpectedExceptionChecker:ERROR"). Need to clarify if it works and if it can report error/warn on current absence of JNI ExceptionCheck calls.
Note that current absence of ExceptionCheck is not crucial because in most of the cases exception means that JVM is already in a bad state. But we are going to use it in a critical service with a high load, at scale, with many dependencies. It is critical that Neuropod Java API is following modern best practices.
The text was updated successfully, but these errors were encountered:
…ll (#462)
### Summary:
Most of JNI calls may cause Java Exception that is not thrown automatically in JNI code. We already check results of calls in some cases. This change also adds ExceptionCheck where this is reasonable. If Java exception detected, we print it, clear and throw custom exception. Issue #434
### Test Plan:
CI
I looked at "Best practices for using the Java Native Interface" https://developer.ibm.com/technologies/java/articles/j-jni/ and found reasonable advises:
Current Neuropod JNI code doesn't have any "env‑>ExceptionCheck". Except a check, JNI code should clear it after all. Need to use some consistent approach for every JNI call that may throw exception.
Note, I looked at Tensorflow Java/JNI code and found that its JNI exception handling is not consistent, it only checks for env‑>ExceptionCheck and never clears it.
"-Xep:ExpectedExceptionChecker:ERROR"). Need to clarify if it works and if it can report error/warn on current absence of JNI ExceptionCheck calls.
Note that current absence of ExceptionCheck is not crucial because in most of the cases exception means that JVM is already in a bad state. But we are going to use it in a critical service with a high load, at scale, with many dependencies. It is critical that Neuropod Java API is following modern best practices.
The text was updated successfully, but these errors were encountered: