diff --git a/libjava/ChangeLog b/libjava/ChangeLog index dabee5148f50..22c7ddbd0bc7 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,12 @@ +2002-09-03 Tom Tromey + + * java/lang/Class.h (_getDeclaredMethod): Declare. + (_getMethod): Now private. + * java/lang/natClass.cc (_getDeclaredMethod): Renamed from + getDeclaredMethod. Now returns NULL on failure. + * java/lang/Class.java (_getDeclaredMethod): Declare. + (getDeclaredMethod): No longer native; implements access checks. + 2002-09-01 Mark Wielaard * gnu/gcj/runtime/NameFinder.java (remove_interpreter): New field. diff --git a/libjava/java/lang/Class.h b/libjava/java/lang/Class.h index 253aa64df1cf..9a8d4183b6fc 100644 --- a/libjava/java/lang/Class.h +++ b/libjava/java/lang/Class.h @@ -160,6 +160,9 @@ private: java::lang::reflect::Method *getPrivateMethod (jstring, JArray *); java::security::ProtectionDomain *getProtectionDomain0 (); + java::lang::reflect::Method *_getMethod (jstring, JArray *); + java::lang::reflect::Method *_getDeclaredMethod (jstring, JArray *); + public: JArray *getFields (void); @@ -167,7 +170,6 @@ public: void getSignature (java::lang::StringBuffer *buffer); static jstring getSignature (JArray *, jboolean is_constructor); - java::lang::reflect::Method *_getMethod (jstring, JArray *); JArray *getMethods (void); inline jint getModifiers (void) diff --git a/libjava/java/lang/Class.java b/libjava/java/lang/Class.java index 12306da80618..cc1cc40f2a48 100644 --- a/libjava/java/lang/Class.java +++ b/libjava/java/lang/Class.java @@ -65,9 +65,31 @@ public final class Class implements Serializable public native Field getDeclaredField (String fieldName) throws NoSuchFieldException, SecurityException; public native Field[] getDeclaredFields () throws SecurityException; - public native Method getDeclaredMethod (String methodName, - Class[] parameterTypes) - throws NoSuchMethodException, SecurityException; + + private native Method _getDeclaredMethod (String methodName, + Class[] parameterTypes); + + public Method getDeclaredMethod (String methodName, Class[] parameterTypes) + throws NoSuchMethodException, SecurityException + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + { + sm.checkMemberAccess(this, Member.DECLARED); + Package p = getPackage(); + if (p != null) + sm.checkPackageAccess(p.getName()); + } + + if ("".equals(methodName) || "".equals(methodName)) + throw new NoSuchMethodException(methodName); + + Method m = _getDeclaredMethod(methodName, parameterTypes); + if (m == null) + throw new NoSuchMethodException (methodName); + return m; + } + public native Method[] getDeclaredMethods () throws SecurityException; // This is marked as unimplemented in the JCL book. diff --git a/libjava/java/lang/natClass.cc b/libjava/java/lang/natClass.cc index 43b79adc9b63..fca074152cee 100644 --- a/libjava/java/lang/natClass.cc +++ b/libjava/java/lang/natClass.cc @@ -315,8 +315,8 @@ java::lang::Class::getSignature (JArray *param_types, } java::lang::reflect::Method * -java::lang::Class::getDeclaredMethod (jstring name, - JArray *param_types) +java::lang::Class::_getDeclaredMethod (jstring name, + JArray *param_types) { jstring partial_sig = getSignature (param_types, false); jint p_len = partial_sig->length(); @@ -324,7 +324,6 @@ java::lang::Class::getDeclaredMethod (jstring name, int i = isPrimitive () ? 0 : method_count; while (--i >= 0) { - // FIXME: access checks. if (_Jv_equalUtf8Consts (methods[i].name, utf_name) && _Jv_equaln (methods[i].signature, partial_sig, p_len)) { @@ -336,7 +335,7 @@ java::lang::Class::getDeclaredMethod (jstring name, return rmethod; } } - throw new java::lang::NoSuchMethodException; + return NULL; } JArray *