JDK-4067541 : (jni) ExceptionDescribe has the side affect of clearing exception
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.1.3
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1997-07-25
  • Updated: 2002-05-17
  • Resolved: 2002-05-17
Description

Name: rlT66838			Date: 07/25/97


1.  Build test.class and native.dll using the files below.
2.  run "java test".
You will see that that the native method returned
even though there should still be a thrown exception.

The problem is caused by the fact the exceptionDescribe
in exceptions.c uses execute_java_dynamic_method
to call printStackTrace.  execute_java_dynamic_method
clears any thrown exceptions right before it calls
the java method.


/* begin test.java */
class TestExcept2 extends Exception
{
}

class test
{
    public static void main( String[] args )
    {
        test t = new test();

        t.useJNI();

        System.out.println("useJNI returned");
    }

    public void throwExcept2() throws TestExcept2
    {
        throw new TestExcept2();
    }

    public native void useJNI();

    static
    {
        System.loadLibrary("native");
    }

}
/* end test.java */

/* begin native.cpp */
#include <jni.h>
#include "test.h"
#include <stdio.h>

extern "C"
{


JNIEXPORT void JNICALL Java_test_useJNI
  (JNIEnv * env, jobject o)
{

    jclass jc1, jc2;
    jobject jo1;
    int i;
    jmethodID id;


    printf("ExceptionOccurred\n=============================================\n");
    jc1 = env->GetObjectClass( o );
    id = ( jmethodID ) env->GetMethodID( jc1, "throwExcept2", "()V");
    env->CallVoidMethod( o, id );
    jo1 = env->ExceptionOccurred();

    printf("ExceptionDescribe\n=============================================\n");
    env->ExceptionDescribe();


}

}
/* end native.cpp */
company - Symantec Corp. , email - ###@###.###
======================================================================

Comments
WORK AROUND Name: rlT66838 Date: 07/25/97 ======================================================================
11-06-2004

EVALUATION Two possible fixes: save the exception object and rethrow it after exceptionDescribe, or rewrite ExceptionDescribe in native code. sheng.liang@Eng 1997-08-05 A third option: Change the spec to say ExceptionDescribe clears the exception. sheng.liang@Eng 1998-04-22 Looks like this is addressed in JDK 1.4 or later. Closing as not a bug anymore.. ###@###.### 2002-05-17
22-04-1998