[kaffe] CVS kaffe (dalibor): improved exception message when a method is not found
Kaffe CVS
Kaffe Mailing List <kaffe@kaffe.org>
Thu Aug 21 04:02:02 2003
PatchSet 3967
Date: 2003/08/21 10:59:29
Author: dalibor
Branch: HEAD
Tag: (none)
Log:
improved exception message when a method is not found
Members:
ChangeLog:1.1565->1.1566
libraries/clib/native/Class.c:1.67->1.68
libraries/javalib/java/lang/Class.java:1.45->1.46
test/regression/ProcessClassInst.java:1.8->1.9
test/regression/ProcessClassStop.java:1.7->1.8
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1565 kaffe/ChangeLog:1.1566
--- kaffe/ChangeLog:1.1565 Wed Aug 20 14:32:05 2003
+++ kaffe/ChangeLog Thu Aug 21 10:59:29 2003
@@ -1,3 +1,19 @@
+2003-08-21 Dalibor Topic <robilad@kaffe.org>
+
+ * libraries/clib/native/Class.c:
+ (java_lang_Class_getMethod0) changed to return NULL on a failed
+ lookup. Added documentation.
+
+ * libraries/javalib/java/lang/Class.java:
+ (getDeclaredMethod, getMethod) use lookupMethod.
+ (lookupMethod) new helper method. Throw an exception if
+ java_lang_Class_getMethod0 returns null. Improved exception
+ message to include class and parameter types of not found method.
+
+ * test/regression/ProcessClassInst.java,
+ test/regression/ProcessClassStop.java:
+ Fixed line numbers in expected results.
+
2003-08-20 Dalibor Topic <robilad@kaffe.org>
* libraries/javalib/kaffe/net/DefaultURLStreamHandlerFactory.java:
Index: kaffe/libraries/clib/native/Class.c
diff -u kaffe/libraries/clib/native/Class.c:1.67 kaffe/libraries/clib/native/Class.c:1.68
--- kaffe/libraries/clib/native/Class.c:1.67 Sun Aug 10 12:41:08 2003
+++ kaffe/libraries/clib/native/Class.c Thu Aug 21 10:59:30 2003
@@ -782,6 +782,16 @@
return (0);
}
+/**
+ * looks up a declared method.
+ *
+ * @param this class where to start looking
+ * @param name name of method we're looking for
+ * @param arr parameter types of the method
+ * @param declared true if the method is supposed to be declared in this class
+ *
+ * @return a method, if it can be found. NULL otherwise.
+ */
Hjava_lang_reflect_Method*
java_lang_Class_getMethod0(struct Hjava_lang_Class* this, struct Hjava_lang_String* name, HArrayOfObject* arr, jboolean declared)
{
@@ -813,12 +823,7 @@
}
}
- /* like SignalError, except that the name of the class that is
- * not found becomes the error message
- */
- throwException((struct Hjava_lang_Throwable*)execute_java_constructor(
- "java.lang.NoSuchMethodException", 0, 0,
- "(Ljava/lang/String;)V", name));
+ return NULL;
}
struct Hjava_lang_reflect_Constructor*
Index: kaffe/libraries/javalib/java/lang/Class.java
diff -u kaffe/libraries/javalib/java/lang/Class.java:1.45 kaffe/libraries/javalib/java/lang/Class.java:1.46
--- kaffe/libraries/javalib/java/lang/Class.java:1.45 Sat Jul 26 23:00:49 2003
+++ kaffe/libraries/javalib/java/lang/Class.java Thu Aug 21 10:59:31 2003
@@ -204,7 +204,8 @@
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkMemberAccess(this, Member.DECLARED);
- return (getMethod0(name, parameterTypes, true));
+
+ return lookupMethod(name, parameterTypes, true);
}
public Method[] getDeclaredMethods() throws SecurityException
@@ -264,7 +265,7 @@
sm.checkMemberAccess(this, Member.PUBLIC );
if( name.equals("<init>") || name.equals("<clinit>") )
throw new NoSuchMethodException();
- return (getMethod0(name, parameterTypes, false));
+ return (lookupMethod(name, parameterTypes, false));
}
native private Method getMethod0(String name, Class[] args, boolean declared);
@@ -369,6 +370,46 @@
native public boolean isInterface();
native public boolean isPrimitive();
+
+
+/**
+ * Lookup a method.
+ *
+ * Internal helper method used to combine common method lookup operations into a single method.
+ *
+ * @param name method name
+ * @param parameterTypes method's list of parameters
+ * @param declared true if the method is supposed to be declared in this class
+ * @return the method, if it can be found.
+ * @exception NoSuchMethodException if no method can be found
+ * @exception SecurityException if access to the method is denied
+ */
+private Method lookupMethod (String name, Class [] parameterTypes, boolean declared) throws NoSuchMethodException, SecurityException {
+
+ Method meth = getMethod0(name, parameterTypes, declared);
+
+ if (meth == null) {
+ StringBuffer buf = new StringBuffer("In class ");
+ buf.append(getName())
+ .append(" there is no method ")
+ .append(name)
+ .append(" (");
+
+ /* write parameter types */
+ for (int i = 0; i < parameterTypes.length; ++i) {
+ buf.append(parameterTypes[i].getName());
+ if (i < parameterTypes.length - 1) {
+ buf.append(", ");
+ }
+ }
+
+ buf.append(')');
+
+ throw new NoSuchMethodException(buf.toString());
+ }
+
+ return meth;
+}
public Object newInstance() throws InstantiationException, IllegalAccessException {
if (Modifier.isAbstract(getModifiers()) || isInterface() || isPrimitive()) {
Index: kaffe/test/regression/ProcessClassInst.java
diff -u kaffe/test/regression/ProcessClassInst.java:1.8 kaffe/test/regression/ProcessClassInst.java:1.9
--- kaffe/test/regression/ProcessClassInst.java:1.8 Sun Jul 27 21:42:26 2003
+++ kaffe/test/regression/ProcessClassInst.java Thu Aug 21 10:59:31 2003
@@ -104,6 +104,6 @@
java.lang.NoClassDefFoundError: Base
at java.lang.Class.getConstructor0 (Class.java)
at java.lang.Class.getDeclaredConstructor (Class.java:174)
- at java.lang.Class.newInstance (Class.java:379)
+ at java.lang.Class.newInstance (Class.java:420)
at ProcessClassInst.main (ProcessClassInst.java:72)
*/
Index: kaffe/test/regression/ProcessClassStop.java
diff -u kaffe/test/regression/ProcessClassStop.java:1.7 kaffe/test/regression/ProcessClassStop.java:1.8
--- kaffe/test/regression/ProcessClassStop.java:1.7 Sun Jul 27 21:42:26 2003
+++ kaffe/test/regression/ProcessClassStop.java Thu Aug 21 10:59:31 2003
@@ -107,6 +107,6 @@
java.lang.NoClassDefFoundError: Base
at java.lang.Class.getConstructor0 (Class.java)
at java.lang.Class.getDeclaredConstructor (Class.java:174)
- at java.lang.Class.newInstance (Class.java:379)
+ at java.lang.Class.newInstance (Class.java:420)
at ProcessClassStop.main (ProcessClassStop.java:74)
*/