author | tschatzl |
Wed, 19 Aug 2015 13:47:40 +0200 | |
changeset 32377 | 5ee15c417d02 |
parent 27402 | 5c4675ddc00c |
child 41705 | 332239c052cc |
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 order |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
29 |
* @run main TestInterfaceOrder |
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 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
32 |
import java.util.List; |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
33 |
import java.util.Arrays; |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
34 |
import java.util.ArrayList; |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
35 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
36 |
public class TestInterfaceOrder { |
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 |
public static void main(java.lang.String[] args) { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
40 |
//Trigger initialization |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
41 |
C c = new C(); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
42 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
43 |
List<Class<?>> expectedCInitOrder = Arrays.asList(I.class, J.class, A.class, K.class, B.class, L.class, C.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
44 |
if (!cInitOrder.equals(expectedCInitOrder)) { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
45 |
throw new RuntimeException(String.format("Class initialization order %s not equal to expected order %s", cInitOrder, expectedCInitOrder)); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
46 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
47 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
48 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
49 |
interface I { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
50 |
boolean v = TestInterfaceOrder.out(I.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
51 |
default void i() {} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
52 |
} |
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 |
interface J extends I { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
55 |
boolean v = TestInterfaceOrder.out(J.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
56 |
default void j() {} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
57 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
58 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
59 |
static class A implements J { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
60 |
static boolean v = TestInterfaceOrder.out(A.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
61 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
62 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
63 |
interface K extends I { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
64 |
boolean v = TestInterfaceOrder.out(K.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
65 |
default void k() {} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
66 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
67 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
68 |
static class B extends A implements K { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
69 |
static boolean v = TestInterfaceOrder.out(B.class); |
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 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
72 |
interface L { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
73 |
boolean v = TestInterfaceOrder.out(L.class); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
74 |
default void l() {} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
75 |
} |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
76 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
77 |
static class C extends B implements L { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
78 |
static boolean v = TestInterfaceOrder.out(C.class); |
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 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
82 |
static boolean out(Class c) { |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
83 |
System.out.println("#: initializing " + c.getName()); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
84 |
cInitOrder.add(c); |
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
85 |
return true; |
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 |
|
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
88 |
} |