acorn@7290: /* acorn@7290: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. acorn@7290: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. acorn@7290: * acorn@7290: * This code is free software; you can redistribute it and/or modify it acorn@7290: * under the terms of the GNU General Public License version 2 only, as acorn@7290: * published by the Free Software Foundation. acorn@7290: * acorn@7290: * This code is distributed in the hope that it will be useful, but WITHOUT acorn@7290: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or acorn@7290: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License acorn@7290: * version 2 for more details (a copy is included in the LICENSE file that acorn@7290: * accompanied this code). acorn@7290: * acorn@7290: * You should have received a copy of the GNU General Public License version acorn@7290: * 2 along with this work; if not, write to the Free Software Foundation, acorn@7290: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. acorn@7290: * acorn@7290: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA acorn@7290: * or visit www.oracle.com if you need additional information or have any acorn@7290: * questions. acorn@7290: * acorn@7290: */ acorn@7290: acorn@7290: /* acorn@7290: * @test acorn@7290: * @bug 8034275 acorn@7290: * @summary [JDK 8u40] Test interface initialization order acorn@7290: * @run main TestInterfaceOrder acorn@7290: */ acorn@7290: acorn@7290: import java.util.List; acorn@7290: import java.util.Arrays; acorn@7290: import java.util.ArrayList; acorn@7290: acorn@7290: public class TestInterfaceOrder { acorn@7290: static List> cInitOrder = new ArrayList<>(); acorn@7290: acorn@7290: public static void main(java.lang.String[] args) { acorn@7290: //Trigger initialization acorn@7290: C c = new C(); acorn@7290: acorn@7290: List> expectedCInitOrder = Arrays.asList(I.class, J.class, A.class, K.class, B.class, L.class, C.class); acorn@7290: if (!cInitOrder.equals(expectedCInitOrder)) { acorn@7290: throw new RuntimeException(String.format("Class initialization order %s not equal to expected order %s", cInitOrder, expectedCInitOrder)); acorn@7290: } acorn@7290: } acorn@7290: acorn@7290: interface I { acorn@7290: boolean v = TestInterfaceOrder.out(I.class); acorn@7290: default void i() {} acorn@7290: } acorn@7290: acorn@7290: interface J extends I { acorn@7290: boolean v = TestInterfaceOrder.out(J.class); acorn@7290: default void j() {} acorn@7290: } acorn@7290: acorn@7290: static class A implements J { acorn@7290: static boolean v = TestInterfaceOrder.out(A.class); acorn@7290: } acorn@7290: acorn@7290: interface K extends I { acorn@7290: boolean v = TestInterfaceOrder.out(K.class); acorn@7290: default void k() {} acorn@7290: } acorn@7290: acorn@7290: static class B extends A implements K { acorn@7290: static boolean v = TestInterfaceOrder.out(B.class); acorn@7290: } acorn@7290: acorn@7290: interface L { acorn@7290: boolean v = TestInterfaceOrder.out(L.class); acorn@7290: default void l() {} acorn@7290: } acorn@7290: acorn@7290: static class C extends B implements L { acorn@7290: static boolean v = TestInterfaceOrder.out(C.class); acorn@7290: } acorn@7290: acorn@7290: acorn@7290: static boolean out(Class c) { acorn@7290: System.out.println("#: initializing " + c.getName()); acorn@7290: cInitOrder.add(c); acorn@7290: return true; acorn@7290: } acorn@7290: acorn@7290: }