--- a/jdk/src/share/classes/java/lang/invoke/MethodHandleStatics.java Thu May 12 19:27:33 2011 -0700
+++ b/jdk/src/share/classes/java/lang/invoke/MethodHandleStatics.java Thu May 12 19:27:49 2011 -0700
@@ -63,8 +63,17 @@
}
static void checkSpreadArgument(Object av, int n) {
- if (av == null ? n != 0 : ((Object[])av).length != n)
- throw newIllegalArgumentException("Array is not of length "+n);
+ if (av == null) {
+ if (n == 0) return;
+ } else if (av instanceof Object[]) {
+ int len = ((Object[])av).length;
+ if (len == n) return;
+ } else {
+ int len = java.lang.reflect.Array.getLength(av);
+ if (len == n) return;
+ }
+ // fall through to error:
+ throw newIllegalArgumentException("Array is not of length "+n);
}
// handy shared exception makers (they simplify the common case code)
@@ -80,6 +89,9 @@
/*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj) {
return new IllegalArgumentException(message(message, obj));
}
+ /*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj, Object obj2) {
+ return new IllegalArgumentException(message(message, obj, obj2));
+ }
/*non-public*/ static Error uncaughtException(Exception ex) {
Error err = new InternalError("uncaught exception");
err.initCause(ex);
@@ -89,4 +101,8 @@
if (obj != null) message = message + ": " + obj;
return message;
}
+ private static String message(String message, Object obj, Object obj2) {
+ if (obj != null || obj2 != null) message = message + ": " + obj + ", " + obj2;
+ return message;
+ }
}