This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: Fix for PR 2428
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 21 Dec 2001 12:55:49 -0700
- Subject: Patch: FYI: Fix for PR 2428
- Reply-to: tromey at redhat dot com
I'm checking this in.
This is the long-discussed change to never return a `null' class
loader. Actually, we return `null' from getClassLoader for primitive
classes; this is required by the spec. In other situations where
there is not a specified loader, we return the system class loader.
While technically this isn't required, it seems to be a useful
compatibility hack.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
Fix for PR libgcj/2428:
* java/lang/natClass.cc: Include RuntimePermission.h.
(getClassLoader): Define.
* java/lang/Class.h (Class.getClassLoader): Only declare.
Index: java/lang/Class.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Class.h,v
retrieving revision 1.42
diff -u -r1.42 Class.h
--- java/lang/Class.h 2001/12/16 22:28:35 1.42
+++ java/lang/Class.h 2001/12/21 19:46:55
@@ -134,10 +134,7 @@
static jclass forName (jstring className);
JArray<jclass> *getClasses (void);
- java::lang::ClassLoader *getClassLoader (void)
- {
- return loader;
- }
+ java::lang::ClassLoader *getClassLoader (void);
java::lang::reflect::Constructor *getConstructor (JArray<jclass> *);
JArray<java::lang::reflect::Constructor *> *getConstructors (void);
Index: java/lang/natClass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClass.cc,v
retrieving revision 1.49
diff -u -r1.49 natClass.cc
--- java/lang/natClass.cc 2001/12/15 08:31:48 1.49
+++ java/lang/natClass.cc 2001/12/21 19:46:56
@@ -43,6 +43,7 @@
#include <java/lang/NoSuchMethodException.h>
#include <java/lang/Thread.h>
#include <java/lang/NullPointerException.h>
+#include <java/lang/RuntimePermission.h>
#include <java/lang/System.h>
#include <java/lang/SecurityManager.h>
#include <java/lang/StringBuffer.h>
@@ -102,6 +103,29 @@
return forName (className, true, NULL);
}
+java::lang::ClassLoader *
+java::lang::Class::getClassLoader (void)
+{
+#if 0
+ // FIXME: the checks we need to do are more complex. See the spec.
+ // Currently we can't implement them.
+ java::lang::SecurityManager *s = java::lang::System::getSecurityManager();
+ if (s != NULL)
+ s->checkPermission (new RuntimePermission (JvNewStringLatin1 ("getClassLoader")));
+#endif
+
+ // The spec requires us to return `null' for primitive classes. In
+ // other cases we have the option of returning `null' for classes
+ // loaded with the bootstrap loader. All gcj-compiled classes which
+ // are linked into the application used to return `null' here, but
+ // that confuses some poorly-written applications. It is a useful
+ // and apparently harmless compatibility hack to simply never return
+ // `null' instead.
+ if (isPrimitive ())
+ return NULL;
+ return loader ? loader : ClassLoader::getSystemClassLoader ();
+}
+
java::lang::reflect::Constructor *
java::lang::Class::getConstructor (JArray<jclass> *param_types)
{
@@ -373,6 +397,8 @@
JArray<jclass> *
java::lang::Class::getClasses (void)
{
+ // FIXME: security checking.
+
// Until we have inner classes, it always makes sense to return an
// empty array.
JArray<jclass> *result
@@ -440,6 +466,8 @@
JArray<java::lang::reflect::Field *> *
java::lang::Class::getFields (void)
{
+ // FIXME: security checking.
+
using namespace java::lang::reflect;
int count = _getFields (NULL, 0);