1.1 --- a/emul/src/main/java/java/lang/reflect/Array.java Fri Jan 18 19:22:49 2013 +0100
1.2 +++ b/emul/src/main/java/java/lang/reflect/Array.java Fri Jan 18 21:04:10 2013 +0100
1.3 @@ -162,7 +162,7 @@
1.4 public static int getLength(Object array)
1.5 throws IllegalArgumentException {
1.6 if (!array.getClass().isArray()) {
1.7 - throw new IllegalArgumentException();
1.8 + throw new IllegalArgumentException("Argument is not an array");
1.9 }
1.10 return length(array);
1.11 }
1.12 @@ -224,8 +224,14 @@
1.13 * length of the specified array
1.14 * @see Array#get
1.15 */
1.16 - public static native byte getByte(Object array, int index)
1.17 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
1.18 + public static byte getByte(Object array, int index)
1.19 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
1.20 + if (array.getClass().getComponentType() != Byte.TYPE) {
1.21 + throw new IllegalArgumentException();
1.22 + }
1.23 + byte[] arr = (byte[]) array;
1.24 + return arr[index];
1.25 + }
1.26
1.27 /**
1.28 * Returns the value of the indexed component in the specified
1.29 @@ -262,8 +268,15 @@
1.30 * length of the specified array
1.31 * @see Array#get
1.32 */
1.33 - public static native short getShort(Object array, int index)
1.34 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
1.35 + public static short getShort(Object array, int index)
1.36 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
1.37 + final Class<?> t = array.getClass().getComponentType();
1.38 + if (t == Short.TYPE) {
1.39 + short[] arr = (short[]) array;
1.40 + return arr[index];
1.41 + }
1.42 + return getByte(array, index);
1.43 + }
1.44
1.45 /**
1.46 * Returns the value of the indexed component in the specified
1.47 @@ -281,8 +294,15 @@
1.48 * length of the specified array
1.49 * @see Array#get
1.50 */
1.51 - public static native int getInt(Object array, int index)
1.52 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
1.53 + public static int getInt(Object array, int index)
1.54 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
1.55 + final Class<?> t = array.getClass().getComponentType();
1.56 + if (t == Integer.TYPE) {
1.57 + int[] arr = (int[]) array;
1.58 + return arr[index];
1.59 + }
1.60 + return getShort(array, index);
1.61 + }
1.62
1.63 /**
1.64 * Returns the value of the indexed component in the specified
1.65 @@ -300,8 +320,15 @@
1.66 * length of the specified array
1.67 * @see Array#get
1.68 */
1.69 - public static native long getLong(Object array, int index)
1.70 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
1.71 + public static long getLong(Object array, int index)
1.72 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
1.73 + final Class<?> t = array.getClass().getComponentType();
1.74 + if (t == Long.TYPE) {
1.75 + long[] arr = (long[]) array;
1.76 + return arr[index];
1.77 + }
1.78 + return getInt(array, index);
1.79 + }
1.80
1.81 /**
1.82 * Returns the value of the indexed component in the specified
1.83 @@ -319,8 +346,15 @@
1.84 * length of the specified array
1.85 * @see Array#get
1.86 */
1.87 - public static native float getFloat(Object array, int index)
1.88 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
1.89 + public static float getFloat(Object array, int index)
1.90 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
1.91 + final Class<?> t = array.getClass().getComponentType();
1.92 + if (t == Float.TYPE) {
1.93 + float[] arr = (float[]) array;
1.94 + return arr[index];
1.95 + }
1.96 + return getLong(array, index);
1.97 + }
1.98
1.99 /**
1.100 * Returns the value of the indexed component in the specified
1.101 @@ -338,8 +372,15 @@
1.102 * length of the specified array
1.103 * @see Array#get
1.104 */
1.105 - public static native double getDouble(Object array, int index)
1.106 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
1.107 + public static double getDouble(Object array, int index)
1.108 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
1.109 + final Class<?> t = array.getClass().getComponentType();
1.110 + if (t == Double.TYPE) {
1.111 + double[] arr = (double[]) array;
1.112 + return arr[index];
1.113 + }
1.114 + return getFloat(array, index);
1.115 + }
1.116
1.117 /**
1.118 * Sets the value of the indexed component of the specified array