From 0d49ec1158291fa15be03b8a7b89c320212c6e94 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 5 Jul 2002 20:40:11 +0000 Subject: re PR libgcj/7060 (getMethod() doesn't search super interface) 2002-07-04 Tom Tromey Jeff Sturm Fix for PR libgcj/7060: * java/lang/Class.h (_getMethod): Renamed from getMethod. * java/lang/natClass.cc (_getMethod): Renamed from getMethod. Recurse into superinterfaces. Don't throw NoSuchMethodException. * java/lang/Class.java (getMethod): New Java implementation; complies with spec. (_getMethod): New native method. Co-Authored-By: Jeff Sturm From-SVN: r55266 --- libjava/java/lang/Class.h | 2 +- libjava/java/lang/Class.java | 25 +++++++++++++++++++++++-- libjava/java/lang/natClass.cc | 18 ++++++++++++++++-- 3 files changed, 40 insertions(+), 5 deletions(-) (limited to 'libjava/java/lang') diff --git a/libjava/java/lang/Class.h b/libjava/java/lang/Class.h index eb33c93..9eb1a5c 100644 --- a/libjava/java/lang/Class.h +++ b/libjava/java/lang/Class.h @@ -166,7 +166,7 @@ public: void getSignature (java::lang::StringBuffer *buffer); static jstring getSignature (JArray *, jboolean is_constructor); - java::lang::reflect::Method *getMethod (jstring, JArray *); + 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 7bd38de..12306da 100644 --- a/libjava/java/lang/Class.java +++ b/libjava/java/lang/Class.java @@ -121,8 +121,29 @@ public final class Class implements Serializable private static final native String getSignature (Class[] parameterTypes, boolean is_construtor); - public native Method getMethod (String methodName, Class[] parameterTypes) - throws NoSuchMethodException, SecurityException; + public native Method _getMethod (String methodName, Class[] parameterTypes); + + public Method getMethod (String methodName, Class[] parameterTypes) + throws NoSuchMethodException, SecurityException + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + { + sm.checkMemberAccess(this, Member.PUBLIC); + Package p = getPackage(); + if (p != null) + sm.checkPackageAccess(p.getName()); + } + + if ("".equals(methodName) || "".equals(methodName)) + throw new NoSuchMethodException(methodName); + + Method m = _getMethod(methodName, parameterTypes); + if (m == null) + throw new NoSuchMethodException (methodName); + return m; + } + private native int _getMethods (Method[] result, int offset); public native Method[] getMethods () throws SecurityException; diff --git a/libjava/java/lang/natClass.cc b/libjava/java/lang/natClass.cc index 5399090..43b79ad 100644 --- a/libjava/java/lang/natClass.cc +++ b/libjava/java/lang/natClass.cc @@ -485,7 +485,7 @@ java::lang::Class::getInterfaces (void) } java::lang::reflect::Method * -java::lang::Class::getMethod (jstring name, JArray *param_types) +java::lang::Class::_getMethod (jstring name, JArray *param_types) { jstring partial_sig = getSignature (param_types, false); jint p_len = partial_sig->length(); @@ -514,7 +514,21 @@ java::lang::Class::getMethod (jstring name, JArray *param_types) } } } - throw new java::lang::NoSuchMethodException; + + // If we haven't found a match, and this class is an interface, then + // check all the superinterfaces. + if (isInterface()) + { + for (int i = 0; i < interface_count; ++i) + { + using namespace java::lang::reflect; + Method *rmethod = interfaces[i]->_getMethod (name, param_types); + if (rmethod != NULL) + return rmethod; + } + } + + return NULL; } // This is a very slow implementation, since it re-scans all the -- cgit v1.1