From 6a00ab92038e717b828161a1222fea0c54592705 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 28 Aug 2009 15:54:30 -0700 Subject: Fix Class.getConstructor("whatever", (Class[]) null). The RI treats null parameterTypes the same as an empty array. This behavior is specified for getMethod, but only implied for getConstructor. This patch: * Fixes getConstructor. * Improves javadoc for Class methods taking "Class... parameterTypes". * Adds tests for both getConstructor and getMethod (which was already correct). * Removes a line of debugging output to System.out. Bug: 1824973 --- luni-kernel/src/main/java/java/lang/Class.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'luni-kernel/src') diff --git a/luni-kernel/src/main/java/java/lang/Class.java b/luni-kernel/src/main/java/java/lang/Class.java index 6adf4db..b8e3903 100644 --- a/luni-kernel/src/main/java/java/lang/Class.java +++ b/luni-kernel/src/main/java/java/lang/Class.java @@ -469,6 +469,7 @@ public final class Class implements Serializable, AnnotatedElement, GenericDe * * @param parameterTypes * the parameter types of the requested constructor. + * {@code (Class[]) null} is equivalent to the empty array. * @return the constructor described by {@code parameterTypes}. * @throws NoSuchMethodException * if the constructor can not be found. @@ -587,6 +588,7 @@ public final class Class implements Serializable, AnnotatedElement, GenericDe * * @param parameterTypes * the parameter types of the requested constructor. + * {@code (Class[]) null} is equivalent to the empty array. * @return the constructor described by {@code parameterTypes}. * @throws NoSuchMethodException * if the requested constructor can not be found. @@ -659,12 +661,14 @@ public final class Class implements Serializable, AnnotatedElement, GenericDe sb.append(getSimpleName()); sb.append('('); boolean first = true; - for (Class p : parameterTypes) { - if (!first) { - sb.append(','); + if (parameterTypes != null) { + for (Class p : parameterTypes) { + if (!first) { + sb.append(','); + } + first = false; + sb.append(p.getSimpleName()); } - first = false; - sb.append(p.getSimpleName()); } sb.append(')'); throw new NoSuchMethodException(sb.toString()); @@ -741,6 +745,7 @@ public final class Class implements Serializable, AnnotatedElement, GenericDe * the requested method's name. * @param parameterTypes * the parameter types of the requested method. + * {@code (Class[]) null} is equivalent to the empty array. * @return the method described by {@code name} and {@code parameterTypes}. * @throws NoSuchMethodException * if the requested constructor can not be found. @@ -991,6 +996,7 @@ public final class Class implements Serializable, AnnotatedElement, GenericDe * the requested method's name. * @param parameterTypes * the parameter types of the requested method. + * {@code (Class[]) null} is equivalent to the empty array. * @return the public field specified by {@code name}. * @throws NoSuchMethodException * if the method can not be found. -- cgit v1.1