1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6191224
  27  * @summary D(reflect) Misleading detail string in IllegalArgumentException thrown by Array.get<Type>
  28  * @run main/othervm Test6191224
  29  */
  30 import java.io.*;
  31 import java.lang.reflect.Array;
  32 
  33 public class Test6191224
  34 {
  35   public static void main(String[] args) throws Exception
  36   {
  37     boolean exception_caught = false;
  38     Object[] objArray = {new Integer(Integer.MAX_VALUE)};
  39 
  40 
  41     // this access is legal
  42     try {
  43       System.out.println(Array.get(objArray, 0));
  44       System.out.println("Test #1 PASSES");
  45     } catch(Exception e) {
  46       System.out.println("Test #1 FAILS");
  47       System.exit(1);
  48     }
  49 
  50     // this access is not legal, but needs to generate the proper exception message
  51     try {
  52       System.out.println(Array.getInt(objArray, 0));
  53     } catch(Exception e) {
  54       exception_caught = true;
  55       System.out.println(e);
  56       if (e.getMessage().equals("Argument is not a primitive type array")) {
  57           System.out.println("Test #2 PASSES");
  58       } else {
  59         System.out.println("Test #2 FAILS - incorrect message");
  60         System.exit(1);
  61       }
  62     }
  63     if (!exception_caught) {
  64       System.out.println("Test #2 FAILS - no exception");
  65       System.exit(1);
  66     }
  67 
  68 
  69     // this access is not legal, but needs to generate the proper exception message
  70     exception_caught = false;
  71     try {
  72       System.out.println(Array.getInt(new Object(), 0));
  73     } catch(Exception e) {
  74       exception_caught = true;
  75       System.out.println(e);
  76       if (e.getMessage().equals("Argument is not an array")) {
  77           System.out.println("Test #3 PASSES");
  78       } else {
  79         System.out.println("Test #3 FAILS - incorrect message");
  80         System.exit(1);
  81       }
  82     }
  83     if (!exception_caught) {
  84       System.out.println("Test #3 FAILS - no exception");
  85       System.exit(1);
  86     }
  87   }
  88 }