Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4973054

Need to clarify how to handle pending exceptions in JNI calls

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 1.4.2, 6
    • hotspot
    • b71
    • generic
    • generic

      There seems vague statements related to exception handking in JNI.

      SUN should clarify which functions can be called even if an exception
      is pending in JNI calls.

      ---
      The java JNI web page says,
      (http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/design.html#wp17626)


       "...After an exception has been raised, the native code must first
       clear the exception before making other JNI calls. When there is a
       pending exception, the only JNI functions that are safe to call are
       ExceptionOccurred(), ExceptionDescribe(), and ExceptionClear(). The
       ExceptionDescribe() function prints a debugging message about the
       pending exception. ..."

       According to the statement, we can only call
        ExceptionOccurred()
        ExceptionDescribe()
        ExceptionClear()
       when there is a pending exception.

       however, we found the folllowing part in
       ./j2se/src/share/native/java/io/ObjectStreamClass.c

       -->
       ...
       JNIEXPORT jboolean JNICALL
       Java_java_io_ObjectStreamClass_hasStaticInitializer(JNIEnv *env,
       jclass this,
                                                          jclass clazz)
       {
          jclass superCl = NULL;
          jmethodID superClinitId = NULL;
          jmethodID clinitId =
              (*env)->GetStaticMethodID(env, clazz, "", "()V");
          if (clinitId == NULL) { /* error thrown */
              jthrowable th = (*env)->ExceptionOccurred(env);
              if ((*env)->IsInstanceOf(env, th, noSuchMethodErrCl)) { <=== (*)
                  (*env)->ExceptionClear(env); /* normal return */
              }
              return JNI_FALSE;
          }
       ...
       <--

       Although the web statement says any JNI call should not be called
       before ExceptionClear(), IsInstanceOf() is called.(above (*))
       
       ===========================================================

            ksrini Kumar Srinivasan
            tbaba Tadayuki Baba (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: