This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: JNIEnv->FindClass(JNIEnv *env, const char *name), initialize class?
Tom Tromey wrote:
"David" == David Daney <ddaney@avtrex.com> writes:
static { } blocks won't be called when a class is loaded in a JNI
function via JNIEnv->FindClass(...). But they will be executed on a
Sun JVM.
Is an example needed? Is this a GCJ issue? Ideas?
David> A small test case would be useful.
Yeah, please write it in a form where we can drop it into the
libjava.jni test suite.
Here you go. Main.java calls searchClass.cpp which runs
FindClass("ClassToFind").
The output with a Sun JVM is:
> Hello...
> "Hello..." should have been printed.
From a GCJ compiled application:
> "Hello..." should have been printed.
Sorry, I'm not (yet) familiar with Mauve and work currently on Windows.
I hope this will do it anyway...
If this is a bug it looks like the fix will be a one line change in
jni.cc:_Jv_JNI_FindClass.
Yes, I thought so :-)
thanks
Marco
#include <jni.h>
#ifndef _Included_Main
#define _Included_Main
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_Main_searchClass(JNIEnv *env, jclass c)
{
env->FindClass("ClassToFind");
}
#ifdef __cplusplus
}
#endif
#endif
public class Main
{
public static void main(String[] args)
{
System.loadLibrary("searchClass");
searchClass();
System.out.println("\"Hello...\" should have been printed.");
}
private static native void searchClass();
}
public class ClassToFind
{
static
{
System.out.println("Hello...");
}
}