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