This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Class.forName(...) on Windows
- From: Marco Trudel <mtrudel at gmx dot ch>
- To: java at gcc dot gnu dot org
- Date: Mon, 26 Jun 2006 16:24:25 +0200
- Subject: Class.forName(...) on Windows
Hello List
Because reflection is broken on windows, gcj is practically useless for
real applications. So I'm looking into it. Unfortunately I'm stuck with
a problem.
In the file natClassLoader.cc, method "jclass _Jv_FindClass
(_Jv_Utf8Const *name, java::lang::ClassLoader *loader)",
findLoadedClass(...) is called. Where is this method? I can't find it...
On linux, this returns the class but on windows, this will fail...
Some differences I noticed while debugging (maybe someone has an idea
what could be the source of the problem):
- It seems class.forName() works at least partially. When starting an
application, class.forName("gnu.gcj.convert.Output_8859_1") is
internally called multiple times and this works.
On linux, class.forName("gnu.gcj.convert.Output_UTF8") is called.
- I used this to be able to print the className:
jsize length = _Jv_GetStringUTFLength (className);
char buffer[length];
_Jv_GetStringUTFRegion(className, 0, className->length(), buffer);
printf("\n### loading class %s ###\n", buffer);
On linux, this will output the correct classnames. On windows, there's
rubbish at the end of it (e.g. "Hello1°" instead of "Hello1"). I assume
that's because I didn't finish the buffer with a \0. It could be that
the final step to get the class has the same mistake; so it will work on
linux but don't on windows (slight chance, but who knows...).
- Searching for an own Class that is compiled into the executable has a
difference between linux and windows. On linux, this won't return a
classloader (natClass.cc, method forName()):
jclass caller = _Jv_StackTrace::GetCallingClass (&Class::class$);
if(caller) loader = caller->getClassLoaderInternal();
On windows, it will.
- The big difference seems to be that linux works with UTF-8, Windows
with iso-8859-1. I haven't compiled libiconv...
Any help would really be appreciated...
regards
Marco