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

(cl) ClassLoader.c does not clear a pending exception - JNI spec violation

XMLWordPrintable

        There is violation to JNI rule in ClassLoader.c, in 1.4.2 and 1.5b48.


        ====j2se/src/share/native/java/lang/ClassLoader.c in 1.5betab48 ====
        ........

           329
           330 if ((*env)->ExceptionOccurred(env)) {
           331 JNU_ThrowByNameWithLastError(env, "java/lang/UnsatisfiedLinkError",
           332 "exception occurred in JNI_OnLoad");
           333 JVM_UnloadLibrary(handle);
           334 JNU_ReleaseStringPlatformChars(env, name, cname);
           335 return;
           336 }
           337

        ......

        On the URL,
         http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp17626

        we can find out the following statement.

        .....
        Exception Handling

        There are two ways to handle an exception in native code:

            * The native method can choose to return immediately, causing the exception
              to be thrown in the Java code that initiated the native method call.
            * The native code can clear the exception by calling ExceptionClear(),
             and then execute its own exception-handling code.

        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.
        ...


        In thhe above extracted code, in site an exception occurs,
        JNU_ThrowByNameWithLastError(line #331) is called without ExceptionClear.

        ExceptionClear() should be done before JNU_ThrowByNameWithLastError.

        ================================================================================

              iris Iris Clark
              tbaba Tadayuki Baba (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: