This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: PR 7060 fix


I'm checking this in.

This is basically Jeff's earlier patch with a new Java wrapper that
handles the security checks.

I've added a new Mauve test case for this.

More fixes like this are needed in Class.java.  In particular almost
none of the security code is there.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	Jeff Sturm  <jsturm@one-point.com>

	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.

Index: java/lang/Class.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Class.h,v
retrieving revision 1.45
diff -u -r1.45 Class.h
--- java/lang/Class.h 24 Jun 2002 20:38:47 -0000 1.45
+++ java/lang/Class.h 5 Jul 2002 20:37:33 -0000
@@ -166,7 +166,7 @@
 
   void getSignature (java::lang::StringBuffer *buffer);
   static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
-  java::lang::reflect::Method *getMethod (jstring, JArray<jclass> *);
+  java::lang::reflect::Method *_getMethod (jstring, JArray<jclass> *);
   JArray<java::lang::reflect::Method *> *getMethods (void);
 
   inline jint getModifiers (void)
Index: java/lang/Class.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Class.java,v
retrieving revision 1.12
diff -u -r1.12 Class.java
--- java/lang/Class.java 11 Jun 2002 17:32:55 -0000 1.12
+++ java/lang/Class.java 5 Jul 2002 20:37:34 -0000
@@ -121,8 +121,29 @@
   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 ("<init>".equals(methodName) || "<clinit>".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;
 
Index: java/lang/natClass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClass.cc,v
retrieving revision 1.51
diff -u -r1.51 natClass.cc
--- java/lang/natClass.cc 25 Jun 2002 05:29:20 -0000 1.51
+++ java/lang/natClass.cc 5 Jul 2002 20:37:35 -0000
@@ -485,7 +485,7 @@
 }
 
 java::lang::reflect::Method *
-java::lang::Class::getMethod (jstring name, JArray<jclass> *param_types)
+java::lang::Class::_getMethod (jstring name, JArray<jclass> *param_types)
 {
   jstring partial_sig = getSignature (param_types, false);
   jint p_len = partial_sig->length();
@@ -514,7 +514,21 @@
 	    }
 	}
     }
-  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]