author | igerasim |
Tue, 25 Aug 2015 19:45:07 +0300 | |
changeset 32276 | 2d5fcc89e099 |
parent 27402 | 5c4675ddc00c |
child 34303 | 9e271398a718 |
permissions | -rw-r--r-- |
27402
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
1 |
/* |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
4 |
* |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
8 |
* |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
13 |
* accompanied this code). |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
14 |
* |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
18 |
* |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
21 |
* questions. |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
22 |
* |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
23 |
*/ |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
24 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
25 |
/* |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
26 |
* @test |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
27 |
* @bug 8034275 |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
28 |
* @summary [JDK 8u40] Test interface initialization: only for interfaces declaring default methods |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
29 |
* @run main TestInterfaceInit |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
30 |
*/ |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
31 |
import java.util.List; |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
32 |
import java.util.Arrays; |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
33 |
import java.util.ArrayList; |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
34 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
35 |
public class TestInterfaceInit { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
36 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
37 |
static List<Class<?>> cInitOrder = new ArrayList<>(); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
38 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
39 |
// Declares a default method and initializes |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
40 |
interface I { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
41 |
boolean v = TestInterfaceInit.out(I.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
42 |
default void x() {} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
43 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
44 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
45 |
// Declares a default method and initializes |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
46 |
interface J extends I { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
47 |
boolean v = TestInterfaceInit.out(J.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
48 |
default void x() {} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
49 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
50 |
// No default method, does not initialize |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
51 |
interface JN extends J { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
52 |
boolean v = TestInterfaceInit.out(JN.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
53 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
54 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
55 |
// Declares a default method and initializes |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
56 |
interface K extends I { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
57 |
boolean v = TestInterfaceInit.out(K.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
58 |
default void x() {} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
59 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
60 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
61 |
// No default method, does not initialize |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
62 |
interface KN extends K { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
63 |
boolean v = TestInterfaceInit.out(KN.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
64 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
65 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
66 |
interface L extends JN, KN { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
67 |
boolean v = TestInterfaceInit.out(L.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
68 |
default void x() {} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
69 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
70 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
71 |
public static void main(String[] args) { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
72 |
// Trigger initialization |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
73 |
boolean v = L.v; |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
74 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
75 |
List<Class<?>> expectedCInitOrder = Arrays.asList(I.class,J.class,K.class,L.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
76 |
if (!cInitOrder.equals(expectedCInitOrder)) { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
77 |
throw new RuntimeException(String.format("Class initialization array %s not equal to expected array %s", cInitOrder, expectedCInitOrder)); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
78 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
79 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
80 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
81 |
static boolean out(Class c) { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
82 |
System.out.println("#: initializing " + c.getName()); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
83 |
cInitOrder.add(c); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
84 |
return true; |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
85 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
86 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
87 |
} |