<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>1412</bug_id>
          
          <creation_ts>2019-12-06 08:33:28 +0100</creation_ts>
          <short_desc>JNI: Check &amp; Handle Exception after calling back into Java</short_desc>
          <delta_ts>2019-12-06 10:16:36 +0100</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>General</product>
          <component>generic</component>
          <version>tbd</version>
          <rep_platform>All</rep_platform>
          <op_sys>all</op_sys>
          <bug_status>IN_PROGRESS</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P4</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Sven Gothel">sgothel</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          
          
          <cf_type>POLICY</cf_type>
          <cf_scm_refs>jogl ddc29141207d9c69f8558265a464cdc4bc014d65
gluegen 5736716ed0598c97273583717ffb9d22a60ca7a4
jogl a8c2de110a2254af137a3d99007cc77e3ecd8078
jogl abde7e96c8ea8f36b48e99ed62029bf0e178a8fa</cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>6425</commentid>
    <comment_count>0</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-12-06 08:33:28 +0100</bug_when>
    <thetext>java -Xcheck:jni ... may disclose occurrences like:

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

These should be handles in the form:

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

&quot;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.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6432</commentid>
    <comment_count>5</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-12-06 09:34:34 +0100</bug_when>
    <thetext>https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#Call_type_Method_routines

THROWS:
Exceptions raised during the execution of the Java method.


+++

https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#java_exceptions</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6433</commentid>
    <comment_count>6</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-12-06 10:16:36 +0100</bug_when>
    <thetext>(In reply to Sven Gothel from comment #3)
&gt; a8c2de110a2254af137a3d99007cc77e3ecd8078
&gt; NEWT Check &amp; Handle Exception after calling back into Java (NewtCommon.c)

fixed with commit abde7e96c8ea8f36b48e99ed62029bf0e178a8fa</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>