This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: loading a class twice
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Subject: Patch: FYI: loading a class twice
- From: Tom Tromey <tromey at redhat dot com>
- Date: 05 Sep 2001 11:59:13 -0600
- Cc: Corey Minyard <minyard at acm dot com>
- Reply-To: tromey at redhat dot com
I'm checking this in. This is a reworked version of a patch from
Corey Minyard. I changed his patch to throw an error instead of
printing a message to stderr. This seems more correct to me.
Tom
Index: ChangeLog
from Corey Minyard <minyard@acm.org>
Tom Tromey <tromey@redhat.com>
* java/lang/natClassLoader.cc: Include VirtualMachineError.h
(_Jv_RegisterClassHookDefault): Throw error if a class is
registered twice.
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.35
diff -u -r1.35 natClassLoader.cc
--- java/lang/natClassLoader.cc 2001/09/01 01:26:13 1.35
+++ java/lang/natClassLoader.cc 2001/09/05 17:46:07
@@ -33,6 +33,7 @@
#include <java/lang/ClassNotFoundException.h>
#include <java/lang/ClassCircularityError.h>
#include <java/lang/IncompatibleClassChangeError.h>
+#include <java/lang/VirtualMachineError.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/Runtime.h>
#include <java/lang/StringBuffer.h>
@@ -453,6 +454,22 @@
_Jv_RegisterClassHookDefault (jclass klass)
{
jint hash = HASH_UTF (klass->name);
+
+ jclass check_class = loaded_classes[hash];
+
+ // If the class is already registered, don't re-register it.
+ while (check_class != NULL)
+ {
+ if (check_class == klass)
+ {
+ // If you get this, it means you have the same class in two
+ // different libraries.
+ throw new java::lang::VirtualMachineError (JvNewStringLatin1 ("class registered twice"));
+ }
+
+ check_class = check_class->next;
+ }
+
klass->next = loaded_classes[hash];
loaded_classes[hash] = klass;
}