author | mchung |
Fri, 12 May 2017 13:29:38 -0700 | |
changeset 45139 | 7be55dfa1742 |
parent 41293 | 871b2f487dc0 |
permissions | -rw-r--r-- |
41293
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
1 |
/* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
4 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
8 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
13 |
* accompanied this code). |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
14 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
18 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
21 |
* questions. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
22 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
23 |
*/ |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
24 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
25 |
/* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
26 |
* @test |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
27 |
* @bug 8163969 |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
28 |
* @summary Interface initialization was crashing on this because the wrong class was getting |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
29 |
* initialization error. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
30 |
* @run main CyclicInterfaceInit |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
31 |
*/ |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
32 |
/** |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
33 |
* This snippet crashes with |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
34 |
* - Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13) |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
35 |
*/ |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
36 |
public class CyclicInterfaceInit { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
37 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
38 |
interface Base { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
39 |
static final Object CONST = new Target(){}.someMethod(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
40 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
41 |
default void important() { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
42 |
// Super interfaces with default methods get initialized (JLS 12.4.1) |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
43 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
44 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
45 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
46 |
static boolean out(String c) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
47 |
System.out.println("initializing " + c); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
48 |
return true; |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
49 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
50 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
51 |
interface Target extends Base { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
52 |
boolean v = CyclicInterfaceInit.out("Target"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
53 |
default Object someMethod() { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
54 |
throw new RuntimeException(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
55 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
56 |
// Target can be fully initialized before initializating Base because Target doesn't |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
57 |
// initiate the initialization of Base. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
58 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
59 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
60 |
static class InnerBad implements Target {} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
61 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
62 |
public static void main(String[] args) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
63 |
try { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
64 |
new Target() {}; // Creates inner class that causes initialization of super interfaces |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
65 |
} catch (ExceptionInInitializerError e) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
66 |
System.out.println("ExceptionInInitializerError thrown as expected"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
67 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
68 |
// Try again, InnerBad instantiation should throw NoClassdefFoundError |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
69 |
// because Base is marked erroneous due to previous exception during initialization |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
70 |
try { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
71 |
InnerBad ig = new InnerBad(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
72 |
throw new RuntimeException("FAILED- initialization of InnerBad should throw NCDFE"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
73 |
} catch (NoClassDefFoundError e) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
74 |
System.out.println("NoClassDefFoundError thrown as expected"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
75 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
76 |
// Target is already initialized. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
77 |
System.out.println("Target.v is " + Target.v); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
78 |
// shouldn't throw any exceptions. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
79 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
80 |
} |