Bug 1412

Summary: JNI: Check & Handle Exception after calling back into Java
Product: [JogAmp] General Reporter: Sven Gothel <sgothel>
Component: genericAssignee: Sven Gothel <sgothel>
Status: IN_PROGRESS ---    
Severity: normal    
Priority: P4    
Version: tbd   
Hardware: All   
OS: all   
Type: POLICY SCM Refs:
jogl ddc29141207d9c69f8558265a464cdc4bc014d65 gluegen 5736716ed0598c97273583717ffb9d22a60ca7a4 jogl a8c2de110a2254af137a3d99007cc77e3ecd8078 jogl abde7e96c8ea8f36b48e99ed62029bf0e178a8fa
Workaround: ---

Description Sven Gothel 2019-12-06 08:33:28 CET
java -Xcheck:jni ... may disclose occurrences like:

"WARNING in native method: JNI call made without checking exceptions when required to from CallStaticObjectMethod"

These should be handles in the form:

 (*env)->CallVoidMethod(env, jobj, ...);
 if( (*env)->ExceptionCheck(env) ) {
     (*env)->ExceptionDescribe(env);
     (*env)->ExceptionClear(env);
     // Optionally throw exception to java 
 }
Comment 1 Sven Gothel 2019-12-06 08:44:45 CET
ddc29141207d9c69f8558265a464cdc4bc014d65
JNI: NEWT Check & Handle Exception after calling back into Java (X11Display + X11Window)
Comment 2 Sven Gothel 2019-12-06 09:10:57 CET
5736716ed0598c97273583717ffb9d22a60ca7a4
JNI: GlueGen JavaEmitter: Check & Handle Exception after calling back into Java
    
    The generated JNI code JVMUtil_NewDirectByteBufferCopy(..)
    calls Buffers.newDirectByteBuffer(..) and potential exceptions should be checked.
Comment 3 Sven Gothel 2019-12-06 09:21:45 CET
a8c2de110a2254af137a3d99007cc77e3ecd8078
NEWT Check & Handle Exception after calling back into Java (NewtCommon.c)
Comment 4 Sven Gothel 2019-12-06 09:26:41 CET
https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.vm.80.doc/docs/jni_exceptions.html

"A JNI function with a return code always sets an error if an exception is pending. You do not need to check for exceptions if a JNI function returns success, but you must check for an exception in an error case. If you do not check, the next time you go through the JNI, the JNI code detects a pending exception and throws it. An exception can be difficult to debug if it is thrown later and, possibly, at a different point in the code from the point at which it was created."
Comment 6 Sven Gothel 2019-12-06 10:16:36 CET
(In reply to Sven Gothel from comment #3)
> a8c2de110a2254af137a3d99007cc77e3ecd8078
> NEWT Check & Handle Exception after calling back into Java (NewtCommon.c)

fixed with commit abde7e96c8ea8f36b48e99ed62029bf0e178a8fa