#55 jni FindClass bug, affects JClassImpl::getClass

closed-fixed
nobody
None
5
2005-01-07
2004-07-28
Anonymous
No

There is a 'bug' (or documentation error) in the jni
method FindClass.

This:

jclass a_class = env->FindClass( "[java/lang/String" );

throws a NoClassDefFoundError, but this works fine:

jclass a_class = env->FindClass( "[Ljava/lang/String;" );

as does:

jclass a_class = env->FindClass( "Ljava/lang/String;" );

Therefore, in JClassImpl::getClass I think you need to
change to:

jclass localClass = env->FindClass( getNameAsType
().c_str() );

See also, JDC bug report 290129.

Discussion

  • Gili Tzabari

    Gili Tzabari - 2004-12-04

    Logged In: YES
    user_id=80628

    According to the JDK source-code and other sources I've seen
    floating around you're supposed to use "java/lang/String"
    instead of the other variants you've mentioned above (i.e.
    the current Jace implementation is correct).

    I'm not exactly sure why you reported this issue. Did you
    run into a case where Jace was invoking FindClass() with an
    incorrect argument? Please clarify.

    Thanks,
    Gili

     
  • n_toze

    n_toze - 2005-01-04

    Logged In: YES
    user_id=1114997

    I think it was the following that gave the problem:

    bool b = jace::instanceof< JArray< String > >( an_item );

    When I tried it the FindClass("[java/lang/String") which the
    original code uses (via getClass) which should work, didn't
    work; but FindClass("[Ljava/lang/String;") which shouldn't
    work, did work.

     
  • n_toze

    n_toze - 2005-01-04

    Logged In: YES
    user_id=1114997

    More concretely, this doesn't work:

    e.g. compile like:
    cl -Ic:\j2sdk1.4.2_05\include -Ic:\j2sdk1.4.2_05
    \include\win32 -Ox -TC -MT findtest.c -link c:\j2sdk1.4.2_05
    \lib\jvm.lib

    --------
    #include <jni.h>

    main()
    {
    JNIEnv* env;
    JavaVM* jvm;
    JavaVMInitArgs vm_args = {0};
    jint res;
    jclass cls = 0;

    vm_args.version = JNI_VERSION_1_2;
    res = JNI_CreateJavaVM(&jvm, (void**)
    &env,&vm_args);

    // Uncommenting the following lines causes the other
    FindClass calls to fail.
    // cls = (*env)->FindClass(env, "[java/lang/Integer" );
    // if ( cls == 0 ) {
    // printf( "Can't find [java/lang/Integer\n");
    // }
    // else { printf("hurray it works as specified");}

    cls = (*env)->FindClass
    (env, "[Ljava/lang/Integer;" );
    if ( cls == 0 ) {
    printf( "Can't find [Ljava/lang/Integer;\n");
    }
    else {
    printf( "Can find [Ljava/lang/Integer;\n" );
    }

    cls = (*env)->FindClass(env, "java/lang/Integer" );
    if ( cls == 0 ) {
    printf( "Can't find java/lang/Integer\n");
    }
    else {
    printf( "Can find java/lang/Integer\n" );
    }

    cls = (*env)->FindClass(env, "Ljava/lang/Integer;" );
    if ( cls == 0 ) {
    printf( "Can't find Ljava/lang/Integer;\n");
    }
    else {
    printf( "Can find Ljava/lang/Integer;\n" );
    }
    }

     
  • Gili Tzabari

    Gili Tzabari - 2005-01-07

    Logged In: YES
    user_id=80628

    Fixed in Jace 1.1 RC1_05.

    Gili

     
  • Gili Tzabari

    Gili Tzabari - 2005-01-07
    • status: open --> closed-fixed
     
  • n_toze

    n_toze - 2005-01-07

    Logged In: YES
    user_id=1114997

    Just thought I'd mention that doing the fix suggested above
    wouldn't comply with the _specification_, so might not be
    portable to different java interpreters.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks