8223723: j.l.c.MethodTypeDesc.dropParameterTypes​ throws the undocumented exception: IllegalArgumentException
authorvromero
Tue, 21 May 2019 15:44:00 -0400
changeset 54965 e022b9cb35a5
parent 54964 ec7d6d8effc7
child 54966 508285c7c6f7
8223723: j.l.c.MethodTypeDesc.dropParameterTypes​ throws the undocumented exception: IllegalArgumentException Reviewed-by: rriggs
src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java
src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java
test/jdk/java/lang/constant/MethodTypeDescTest.java
--- a/src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java	Tue May 21 20:53:27 2019 +0200
+++ b/src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java	Tue May 21 15:44:00 2019 -0400
@@ -141,8 +141,8 @@
      * @param end the index after the last parameter to remove
      * @return a {@linkplain MethodTypeDesc} describing the desired method type
      * @throws IndexOutOfBoundsException if {@code start} is outside the half-open
-     * range {[0, parameterCount)}, or {@code end} is outside the closed range
-     * {@code [0, parameterCount]}
+     * range {@code [0, parameterCount)}, or {@code end} is outside the closed range
+     * {@code [0, parameterCount]}, or if {@code start > end}
      */
     MethodTypeDesc dropParameterTypes(int start, int end);
 
--- a/src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java	Tue May 21 20:53:27 2019 +0200
+++ b/src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java	Tue May 21 15:44:00 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -111,10 +111,8 @@
 
     @Override
     public MethodTypeDesc dropParameterTypes(int start, int end) {
-        if (start < 0 || start >= argTypes.length || end < 0 || end > argTypes.length)
+        if (start < 0 || start >= argTypes.length || end < 0 || end > argTypes.length || start > end)
             throw new IndexOutOfBoundsException();
-        else if (start > end)
-            throw new IllegalArgumentException(String.format("Range (%d, %d) not valid for size %d", start, end, argTypes.length));
         ClassDesc[] newArgs = new ClassDesc[argTypes.length - (end - start)];
         System.arraycopy(argTypes, 0, newArgs, 0, start);
         System.arraycopy(argTypes, end, newArgs, start, argTypes.length - end);
--- a/test/jdk/java/lang/constant/MethodTypeDescTest.java	Tue May 21 20:53:27 2019 +0200
+++ b/test/jdk/java/lang/constant/MethodTypeDescTest.java	Tue May 21 15:44:00 2019 -0400
@@ -237,7 +237,7 @@
         try {
             MethodTypeDesc newDesc = mtDesc.dropParameterTypes(1, 0);
             fail("start index > end index should have failed");
-        } catch (IllegalArgumentException ex) {
+        } catch (IndexOutOfBoundsException ex) {
             // good
         }
     }