PATCH: fix libgcj/7060

Andrew Pinski pinskia@physics.uc.edu
Tue Jun 18 17:21:00 GMT 2002


I would make sure the order of _getMethod in Class.h and 
Class.java are in the same place.

Thanks,
Andrew Pinski



On Tuesday, June 18, 2002, at 05:22 , Jeff Sturm wrote:

> Here's a possible fix for libgcj/7060.  It passed my tests.  Full
> regression test pending.
>
> I decided it would be best to invoke getMethod recursively, since
> interfaces may inherit from a tree of other interfaces.  To 
> avoid catching
> NoSuchMethodExceptions I split getMethod into two, introducing a new
> private method.
>
> Is this acceptable?  I'd like it if someone more familiar with the
> class implementation could look it over.
>
> 2002-06-18  Jeff Sturm  <jsturm@one-point.com>
>
> 	Fixes libgcj/7060.
>
> 	* java/lang/Class.h (_getMethod): Add.
> 	* java/lang/Class.java (_getMethod): Add.
> 	* java/lang/natClass.cc (getMethod): Refactor into getMethod and
> 	_getMethod.  Search interface list for methods.
>
> diff -rup gcc-3.1-orig/libjava/java/lang/Class.h 
> gcc-3.1/libjava/java/lang/Class.h
> --- gcc-3.1-orig/libjava/java/lang/Class.h	Fri Dec 21 14:47:50 2001
> +++ gcc-3.1/libjava/java/lang/Class.h	Tue Jun 18 11:46:28 2002
> @@ -153,6 +153,7 @@ private:
>    jint _getFields (JArray<java::lang::reflect::Field *> 
> *result, jint offset);
>    JArray<java::lang::reflect::Constructor *> *_getConstructors 
> (jboolean);
>    java::lang::reflect::Field *getField (jstring, jint);
> +  java::lang::reflect::Method *_getMethod (jstring, jstring);
>    jint _getMethods (JArray<java::lang::reflect::Method *> *result,
>  		    jint offset);
>    java::lang::reflect::Field *getPrivateField (jstring);
> diff -rup gcc-3.1-orig/libjava/java/lang/Class.java 
> gcc-3.1/libjava/java/lang/Class.java
> --- gcc-3.1-orig/libjava/java/lang/Class.java	Wed Apr 25 11:45:12 2001
> +++ gcc-3.1/libjava/java/lang/Class.java	Tue Jun 18 11:47:29 2002
> @@ -121,6 +121,7 @@ public final class Class implements Seri
>    private static final native String getSignature (Class[] 
> parameterTypes,
>  						   boolean is_construtor);
>
> +  private native Method _getMethod (String methodName, String 
> partialSig);
>    public native Method getMethod (String methodName, Class[] 
> parameterTypes)
>      throws NoSuchMethodException, SecurityException;
>    private native int _getMethods (Method[] result, int offset);
> diff -rup gcc-3.1-orig/libjava/java/lang/natClass.cc 
> gcc-3.1/libjava/java/lang/natClass.cc
> --- gcc-3.1-orig/libjava/java/lang/natClass.cc	Fri Dec 21 14:47:50 2001
> +++ gcc-3.1/libjava/java/lang/natClass.cc	Tue Jun 18 17:04:07 2002
> @@ -492,12 +492,13 @@ java::lang::Class::getInterfaces (void)
>  }
>
>  java::lang::reflect::Method *
> -java::lang::Class::getMethod (jstring name, JArray<jclass> 
> *param_types)
> +java::lang::Class::_getMethod (jstring name, jstring partial_sig)
>  {
> -  jstring partial_sig = getSignature (param_types, false);
> -  jint p_len = partial_sig->length();
>    _Jv_Utf8Const *utf_name = _Jv_makeUtf8Const (name);
> -  for (Class *klass = this; klass; klass = klass->getSuperclass())
> +  jint p_len = partial_sig->length();
> +
> +  // Search this and each super class in turn for the named method.
> +  for (jclass klass = this; klass; klass = klass->getSuperclass())
>      {
>        int i = klass->isPrimitive () ? 0 : klass->method_count;
>        while (--i >= 0)
> @@ -515,13 +516,39 @@ java::lang::Class::getMethod (jstring na
>
>  	      Method *rmethod = new Method ();
>  	      rmethod->offset = ((char *) (&klass->methods[i])
> 				 - (char *) klass->methods);
>  	      rmethod->declaringClass = klass;
>  	      return rmethod;
>  	    }
>  	}
>      }
> -  throw new java::lang::NoSuchMethodException;
> +
> +  // For interfaces, also search super interfaces.
> +  if (isInterface ())
> +    for (int n = 0; n < interface_count; n++)
> +      {
> +	jclass interface = interfaces[n];
> +	java::lang::reflect::Method *rmethod;
> +
> +	rmethod = interface->_getMethod (name, partial_sig);
> +
> +	if (rmethod)
> +	  return rmethod;
> +      }
> +
> +  return (java::lang::reflect::Method *) 0;
> +}
> +
> +java::lang::reflect::Method *
> +java::lang::Class::getMethod (jstring name, JArray<jclass> 
> *param_types)
> +{
> +  jstring partial_sig = getSignature (param_types, false);
> +  java::lang::reflect::Method *rmethod = _getMethod (name, 
> partial_sig);
> +
> +  if (! rmethod)
> +    throw new java::lang::NoSuchMethodException;
> +
> +  return rmethod;
>  }
>
>  // This is a very slow implementation, since it re-scans all the
>
>
>



More information about the Java-patches mailing list