Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6191224

(reflect) Misleading detail string in IllegalArgumentException thrown by Array.get<Type>

XMLWordPrintable

    • b40
    • generic
    • generic
    • Not verified

        Tried on Solaris 9 JDK 1.5.0_01-ea-b03.

        See the following testcase:

        import java.lang.reflect.Array;
        public class Test2 {
           public static void main (String args[]) {
               Object[] objArray = {new Integer(Integer.MAX_VALUE), new
        Integer(Integer.MIN_VALUE)};
               for(int i=0; i<Array.getLength(objArray); i++){
                   System.out.println(Array.get(objArray,i));
                   System.out.println(Array.getInt(objArray,i));
               }
           }
        }

        Output :
        2147483647
        Exception in thread "main" java.lang.IllegalArgumentException: Argument
        is not an array
               at java.lang.reflect.Array.getInt(Native Method)
               at Test2.main(Test2.java:8)

        The Exception message that it is throwing "Argument is not an
        array", is misleading to the user as the argument is an array.

        Not only for getInt, it behaves the same way for getBoolean, getByte, getFloat, getChar, getDouble, getLong and getShort.
        ###@###.### 2004-11-05 04:17:05 GMT

              cjplummer Chris Plummer
              savadhansunw Seetharama Avadhanam (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: