8157590: MethodHandles.arrayLength() lacks @since tag, implementation throws wrong exception
authormhaupt
Tue, 24 May 2016 09:13:47 +0200
changeset 38472 6d7aed566bf3
parent 38471 7baac1d79ed1
child 38473 39f3b8618e2f
8157590: MethodHandles.arrayLength() lacks @since tag, implementation throws wrong exception Reviewed-by: psandoz
jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Tue May 24 11:28:29 2016 +0800
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Tue May 24 09:13:47 2016 +0200
@@ -118,7 +118,7 @@
                 case SET: return "setElement";
                 case LENGTH: return "length";
             }
-            throw new AssertionError();
+            throw unmatchedArrayAccess(a);
         }
 
         static MethodHandle objectAccessor(ArrayAccess a) {
@@ -127,7 +127,7 @@
                 case SET: return ArrayAccessor.OBJECT_ARRAY_SETTER;
                 case LENGTH: return ArrayAccessor.OBJECT_ARRAY_LENGTH;
             }
-            throw new AssertionError();
+            throw unmatchedArrayAccess(a);
         }
 
         static int cacheIndex(ArrayAccess a) {
@@ -136,7 +136,7 @@
                 case SET: return ArrayAccessor.SETTER_INDEX;
                 case LENGTH: return ArrayAccessor.LENGTH_INDEX;
             }
-            throw new AssertionError();
+            throw unmatchedArrayAccess(a);
         }
 
         static Intrinsic intrinsic(ArrayAccess a) {
@@ -145,10 +145,14 @@
                 case SET: return Intrinsic.ARRAY_STORE;
                 case LENGTH: return Intrinsic.ARRAY_LENGTH;
             }
-            throw new AssertionError();
+            throw unmatchedArrayAccess(a);
         }
     }
 
+    static InternalError unmatchedArrayAccess(ArrayAccess a) {
+        return newInternalError("should not reach here (unmatched ArrayAccess: " + a + ")");
+    }
+
     static final class ArrayAccessor {
         /// Support for array element and length access
         static final int GETTER_INDEX = 0, SETTER_INDEX = 1, LENGTH_INDEX = 2, INDEX_LIMIT = 3;
@@ -218,7 +222,7 @@
                 case SET:    return MethodType.methodType(void.class, arrayArgClass, int.class, elemClass);
                 case LENGTH: return MethodType.methodType(int.class,  arrayArgClass);
             }
-            throw new IllegalStateException("should not reach here");
+            throw unmatchedArrayAccess(access);
         }
         static MethodType correctType(Class<?> arrayClass, ArrayAccess access) {
             Class<?> elemClass = arrayClass.getComponentType();
@@ -227,7 +231,7 @@
                 case SET:    return MethodType.methodType(void.class, arrayClass, int.class, elemClass);
                 case LENGTH: return MethodType.methodType(int.class,  arrayClass);
             }
-            throw new IllegalStateException("should not reach here");
+            throw unmatchedArrayAccess(access);
         }
         static MethodHandle getAccessor(Class<?> arrayClass, ArrayAccess access) {
             String     name = name(arrayClass, access);
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Tue May 24 11:28:29 2016 +0800
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Tue May 24 09:13:47 2016 +0200
@@ -2252,6 +2252,7 @@
      * @return a method handle which can retrieve the length of an array of the given array type
      * @throws NullPointerException if the argument is {@code null}
      * @throws IllegalArgumentException if arrayClass is not an array type
+     * @since 9
      */
     public static
     MethodHandle arrayLength(Class<?> arrayClass) throws IllegalArgumentException {