Patch: reflection bug fix

Tom Tromey tromey@cygnus.com
Wed Jan 5 08:28:00 GMT 2000


I'm checking in this patch.  It fixes a couple bugs in the reflection
code discovered by the Mauve tests I wrote yesterday.

2000-01-04  Tom Tromey  <tromey@cygnus.com>

	* java/lang/Class.h (getSignature): Updated.
	* java/lang/Class.java (getSignature): Updated.
	* java/lang/natClass.cc (getSignature): Added `is_constructor'
	argument.
	(getConstructor): Ensure constructor is public.
	(_getConstructors): Check for public-ness of constructor when
	`declared' is false, not when it is true.

Tom

Index: java/lang/Class.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/Class.h,v
retrieving revision 1.8
diff -u -r1.8 Class.h
--- Class.h	2000/01/04 08:46:52	1.8
+++ Class.h	2000/01/05 05:24:48
@@ -103,7 +103,7 @@
   JArray<jclass> *getInterfaces (void);
 
   void getSignature (java::lang::StringBuffer *buffer);
-  static jstring getSignature (JArray<jclass> *);
+  static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
   java::lang::reflect::Method *getMethod (jstring, JArray<jclass> *);
   JArray<java::lang::reflect::Method *> *getMethods (void);
 
Index: java/lang/Class.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/Class.java,v
retrieving revision 1.4
diff -u -r1.4 Class.java
--- Class.java	2000/01/04 08:46:52	1.4
+++ Class.java	2000/01/05 05:24:48
@@ -89,7 +89,8 @@
   public native Class[] getInterfaces ();
 
   private final native void getSignature (StringBuffer buffer);
-  private static final native String getSignature (Class[] parameterTypes);
+  private static final native String getSignature (Class[] parameterTypes,
+						   boolean is_construtor);
 
   public native Method getMethod (String methodName, Class[] parameterTypes)
     throws NoSuchMethodException, SecurityException;
Index: java/lang/natClass.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natClass.cc,v
retrieving revision 1.9
diff -u -r1.9 natClass.cc
--- natClass.cc	2000/01/04 08:46:52	1.9
+++ natClass.cc	2000/01/05 05:24:53
@@ -101,7 +101,7 @@
 java::lang::reflect::Constructor *
 java::lang::Class::getConstructor (JArray<jclass> *param_types)
 {
-  jstring partial_sig = getSignature (param_types);
+  jstring partial_sig = getSignature (param_types, true);
   jint hash = partial_sig->hashCode ();
 
   int i = isPrimitive () ? 0 : method_count;
@@ -114,7 +114,7 @@
 	  // Found it.  For getConstructor, the constructor must be
 	  // public.
 	  using namespace java::lang::reflect;
-	  if (Modifier::isPublic(methods[i].accflags))
+	  if (! Modifier::isPublic(methods[i].accflags))
 	    break;
 	  Constructor *cons = new Constructor ();
 	  cons->offset = (char *) (&methods[i]) - (char *) methods;
@@ -139,7 +139,7 @@
       if (method->name == NULL
 	  && ! _Jv_equalUtf8Consts (method->name, init_name))
 	continue;
-      if (declared
+      if (! declared
 	  && ! java::lang::reflect::Modifier::isPublic(method->accflags))
 	continue;
       numConstructors++;
@@ -154,7 +154,7 @@
       if (method->name == NULL
 	  && ! _Jv_equalUtf8Consts (method->name, init_name))
 	continue;
-      if (declared
+      if (! declared
 	  && ! java::lang::reflect::Modifier::isPublic(method->accflags))
 	continue;
       java::lang::reflect::Constructor *cons
@@ -169,7 +169,7 @@
 java::lang::reflect::Constructor *
 java::lang::Class::getDeclaredConstructor (JArray<jclass> *param_types)
 {
-  jstring partial_sig = getSignature (param_types);
+  jstring partial_sig = getSignature (param_types, true);
   jint hash = partial_sig->hashCode ();
 
   int i = isPrimitive () ? 0 : method_count;
@@ -277,7 +277,8 @@
 // This doesn't have to be native.  It is an implementation detail
 // only called from the C++ code, though, so maybe this is clearer.
 jstring
-java::lang::Class::getSignature (JArray<jclass> *param_types)
+java::lang::Class::getSignature (JArray<jclass> *param_types,
+				 jboolean is_constructor)
 {
   java::lang::StringBuffer *buf = new java::lang::StringBuffer ();
   buf->append((jchar) '(');
@@ -285,6 +286,8 @@
   for (int i = 0; i < param_types->length; ++i)
     v[i]->getSignature(buf);
   buf->append((jchar) ')');
+  if (is_constructor)
+    buf->append((jchar) 'V');
   return buf->toString();
 }
 
@@ -292,7 +295,7 @@
 java::lang::Class::getDeclaredMethod (jstring name,
 				      JArray<jclass> *param_types)
 {
-  jstring partial_sig = getSignature (param_types);
+  jstring partial_sig = getSignature (param_types, false);
   jint p_len = partial_sig->length();
   _Jv_Utf8Const *utf_name = _Jv_makeUtf8Const (name);
   int i = isPrimitive () ? 0 : method_count;
@@ -446,7 +449,7 @@
 java::lang::reflect::Method *
 java::lang::Class::getMethod (jstring name, JArray<jclass> *param_types)
 {
-  jstring partial_sig = getSignature (param_types);
+  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())


More information about the Java-patches mailing list