# HG changeset patch # User Jaroslav Tulach # Date 1358542266 -3600 # Node ID d962d1330e54f588701763bd614931ce2486b3d8 # Parent 7ca6bd52b6680482b5f67cc93dd40065dc0a0c15 Just autoboxing on Arrays remains diff -r 7ca6bd52b668 -r d962d1330e54 emul/src/main/java/java/lang/reflect/Array.java --- a/emul/src/main/java/java/lang/reflect/Array.java Fri Jan 18 21:21:35 2013 +0100 +++ b/emul/src/main/java/java/lang/reflect/Array.java Fri Jan 18 21:51:06 2013 +0100 @@ -186,8 +186,14 @@ * argument is negative, or if it is greater than or equal to the * length of the specified array */ - public static native Object get(Object array, int index) - throws IllegalArgumentException, ArrayIndexOutOfBoundsException; + public static Object get(Object array, int index) + throws IllegalArgumentException, ArrayIndexOutOfBoundsException { + if (array.getClass().getComponentType().isPrimitive()) { + throw new IllegalArgumentException(); + } else { + return ((Object[])array)[index]; + } + } /** * Returns the value of the indexed component in the specified @@ -399,8 +405,15 @@ * argument is negative, or if it is greater than or equal to * the length of the specified array */ - public static native void set(Object array, int index, Object value) - throws IllegalArgumentException, ArrayIndexOutOfBoundsException; + public static void set(Object array, int index, Object value) + throws IllegalArgumentException, ArrayIndexOutOfBoundsException { + if (array.getClass().getComponentType().isPrimitive()) { + throw new IllegalArgumentException(); + } else { + Object[] arr = (Object[])array; + arr[index] = value; + } + } /** * Sets the value of the indexed component of the specified array diff -r 7ca6bd52b668 -r d962d1330e54 vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java Fri Jan 18 21:21:35 2013 +0100 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java Fri Jan 18 21:51:06 2013 +0100 @@ -74,6 +74,11 @@ int[] arr = (int[]) Array.newInstance(int.class, 5); return (Integer) Array.get(arr, 0); } + @Compare public String verifyObjectArray() { + String[] arr = (String[]) Array.newInstance(String.class, 5); + Array.set(arr, 0, "Hello"); + return (String) Array.get(arr, 0); + } @Compare public int verifyInt() { int[] arr = (int[]) Array.newInstance(int.class, 5); return Array.getInt(arr, 0); @@ -84,9 +89,13 @@ } @Compare public Object verifySetIntToObject() { - Object[] arr = (Object[]) Array.newInstance(Object.class, 5); - Array.setInt(arr, 0, 10); - return Array.get(arr, 0); + try { + Object[] arr = (Object[]) Array.newInstance(Object.class, 5); + Array.setInt(arr, 0, 10); + return Array.get(arr, 0); + } catch (Exception exception) { + return exception.getClass().getName(); + } } @Compare public long verifySetShort() { int[] arr = (int[]) Array.newInstance(int.class, 5);