# HG changeset patch # User Jaroslav Tulach # Date 1362052824 -3600 # Node ID 0b32ef894ba65f1d055dc5bca187d4e471b0b76c # Parent af4001c854384ad3d49dac07460c09f05e3b7676 Can use valueOf to get primitive value from all wrapper types diff -r af4001c85438 -r 0b32ef894ba6 rt/emul/mini/src/main/java/java/lang/reflect/Method.java --- a/rt/emul/mini/src/main/java/java/lang/reflect/Method.java Thu Feb 28 10:39:40 2013 +0100 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Method.java Thu Feb 28 13:00:24 2013 +0100 @@ -512,8 +512,8 @@ args = args.clone(); for (int i = 0; i < types.length; i++) { Class c = types[i]; - if (c.isPrimitive()) { - args[i] = toPrimitive(c, args[i]); + if (c.isPrimitive() && args[i] != null) { + args[i] = toPrimitive(args[i]); } } } @@ -573,41 +573,8 @@ ) private static native Integer fromRaw(Class cls, String m, Object o); - private static Object toPrimitive(Class type, Object o) { - if (type == Integer.TYPE) { - return toRaw("intValue__I", o); - } - if (type == Long.TYPE) { - return toRaw("longValue__J", o); - } - if (type == Double.TYPE) { - return toRaw("doubleValue__D", o); - } - if (type == Float.TYPE) { - return toRaw("floatValue__F", o); - } - if (type == Byte.TYPE) { - return toRaw("byteValue__B", o); - } - if (type == Boolean.TYPE) { - return toRaw("booleanValue__Z", o); - } - if (type == Short.TYPE) { - return toRaw("shortValue__S", o); - } - if (type == Character.TYPE) { - return toRaw("charValue__C", o); - } - if (type.getName().equals("void")) { - return o; - } - throw new IllegalStateException("Can't convert " + o); - } - - @JavaScriptBody(args = { "m", "o" }, - body = "return o[m](o);" - ) - private static native Object toRaw(String m, Object o); + @JavaScriptBody(args = { "o" }, body = "return o.valueOf();") + private static native Object toPrimitive(Object o); /** * Returns {@code true} if this method is a bridge