specify classloader when calling Class.forCanonicalName in Field and Method; tolerate null argument array in Method.invoke

This commit is contained in:
Joel Dice 2009-08-10 07:48:44 -06:00
parent 5c72746d2c
commit 58c3a37277
2 changed files with 15 additions and 4 deletions

View File

@ -53,7 +53,8 @@ public class Field<T> extends AccessibleObject {
}
public Class getType() {
return Class.forCanonicalName(new String(spec, 0, spec.length - 1, false));
return Class.forCanonicalName(class_.getClassLoader(),
new String(spec, 0, spec.length - 1, false));
}
public Object get(Object instance) throws IllegalAccessException {

View File

@ -85,11 +85,13 @@ public class Method<T> extends AccessibleObject
types[index++] = Class.forName(name);
} else {
String name = spec.substring(start, i + 1);
types[index++] = Class.forCanonicalName(name);
types[index++] = Class.forCanonicalName
(class_.getClassLoader(), name);
}
} else {
String name = spec.substring(i, i + 1);
types[index++] = Class.forCanonicalName(name);
types[index++] = Class.forCanonicalName
(class_.getClassLoader(), name);
}
}
} catch (ClassNotFoundException e) {
@ -107,6 +109,13 @@ public class Method<T> extends AccessibleObject
instance = null;
}
if (arguments == null) {
if (parameterCount > 0) {
throw new NullPointerException();
}
arguments = new Object[0];
}
if (arguments.length == parameterCount) {
return invoke(this, instance, arguments);
} else {
@ -125,7 +134,8 @@ public class Method<T> extends AccessibleObject
for (int i = 0; i < spec.length - 1; ++i) {
if (spec[i] == ')') {
return Class.forCanonicalName
(new String(spec, i + 1, spec.length - i - 2, false));
(class_.getClassLoader(),
new String(spec, i + 1, spec.length - i - 2, false));
}
}
throw new RuntimeException();