author | fzhinkin |
Fri, 12 Dec 2014 21:37:37 +0300 | |
changeset 28181 | ce5d307551ea |
parent 26435 | b446202ac824 |
permissions | -rw-r--r-- |
26435
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
1 |
/* |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
4 |
* |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
8 |
* |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
13 |
* accompanied this code). |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
14 |
* |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
18 |
* |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
21 |
* questions. |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
22 |
*/ |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
23 |
|
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
24 |
/* |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
25 |
* @test |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
26 |
* @bug 8055910 |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
27 |
* @summary Arrays.copyOf doesn't perform subtype check |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
28 |
* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestArrayOfNoTypeCheck |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
29 |
* |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
30 |
*/ |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
31 |
|
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
32 |
import java.util.Arrays; |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
33 |
|
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
34 |
public class TestArrayOfNoTypeCheck { |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
35 |
|
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
36 |
static class A { |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
37 |
} |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
38 |
|
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
39 |
static class B extends A { |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
40 |
} |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
41 |
|
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
42 |
static B[] test(A[] arr) { |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
43 |
return Arrays.copyOf(arr, 10, B[].class); |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
44 |
} |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
45 |
|
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
46 |
static public void main(String[] args) { |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
47 |
A[] arr = new A[20]; |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
48 |
for (int i = 0; i < 20000; i++) { |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
49 |
test(arr); |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
50 |
} |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
51 |
A[] arr2 = new A[20]; |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
52 |
arr2[0] = new A(); |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
53 |
boolean exception = false; |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
54 |
try { |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
55 |
test(arr2); |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
56 |
} catch (ArrayStoreException ase) { |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
57 |
exception = true; |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
58 |
} |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
59 |
if (!exception) { |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
60 |
throw new RuntimeException("TEST FAILED: ArrayStoreException not thrown"); |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
61 |
} |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
62 |
} |
b446202ac824
8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents:
diff
changeset
|
63 |
} |