|
1 /* |
|
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 /* |
|
26 * @test |
|
27 * @bug 8154587 |
|
28 * @summary Check that method resolution for invokeinterface of clone() fails |
|
29 * if it cannot find a public method named clone(). |
|
30 * @compile LocalClone.jasm |
|
31 * @run main LocalClone |
|
32 */ |
|
33 |
|
34 // The below .jasm code implements the following java code: |
|
35 // |
|
36 // interface I1 { } |
|
37 // |
|
38 // |
|
39 // public class LocalClone { |
|
40 // |
|
41 // interface I2 extends I1 { } |
|
42 // |
|
43 // |
|
44 // static class C implements I2 { |
|
45 // public Object clone() { |
|
46 // return "In C's clone()"; |
|
47 // } |
|
48 // } |
|
49 // |
|
50 // static Object test(I2 i) { return i.clone(); } |
|
51 // |
|
52 // public static void main(String[] args) { |
|
53 // try { |
|
54 // String s = (String)test(new C()); |
|
55 // throw new RuntimeException("Expected NSME not thrown"); |
|
56 // } catch (java.lang.NoSuchMethodError e) { |
|
57 // if (!e.toString().contains("I2.clone")) { |
|
58 // throw new RuntimeException("Wrong NoSuchMethodError exception thrown"); |
|
59 // } |
|
60 // } |
|
61 // } |
|
62 // } |
|
63 |
|
64 |
|
65 interface I1 version 53:0 { } // end Class I1 |
|
66 |
|
67 |
|
68 interface LocalClone$I2 implements I1 version 53:0 { |
|
69 |
|
70 static abstract interface InnerClass I2=class LocalClone$I2 of class LocalClone; |
|
71 |
|
72 } // end Class LocalClone$I2 |
|
73 |
|
74 |
|
75 super class LocalClone$C implements LocalClone$I2 version 53:0 { |
|
76 |
|
77 Method "<init>":"()V" stack 1 locals 1 { |
|
78 aload_0; |
|
79 invokespecial Method java/lang/Object."<init>":"()V"; |
|
80 return; |
|
81 } |
|
82 |
|
83 public Method clone:"()Ljava/lang/Object;" stack 1 locals 1 { |
|
84 ldc String "In C\'s clone()"; |
|
85 areturn; |
|
86 } |
|
87 |
|
88 static InnerClass C=class LocalClone$C of class LocalClone; |
|
89 static abstract interface InnerClass I2=class LocalClone$I2 of class LocalClone; |
|
90 |
|
91 } // end Class LocalClone$C |
|
92 |
|
93 |
|
94 super public class LocalClone version 53:0 { |
|
95 |
|
96 public Method "<init>":"()V" stack 1 locals 1 { |
|
97 aload_0; |
|
98 invokespecial Method java/lang/Object."<init>":"()V"; |
|
99 return; |
|
100 } |
|
101 |
|
102 static Method test:"(LLocalClone$I2;)Ljava/lang/Object;" stack 1 locals 1 { |
|
103 aload_0; |
|
104 invokeinterface InterfaceMethod LocalClone$I2.clone:"()Ljava/lang/Object;", 1; |
|
105 areturn; |
|
106 } |
|
107 |
|
108 public static Method main:"([Ljava/lang/String;)V" stack 3 locals 2 { |
|
109 try t0; |
|
110 new class LocalClone$C; |
|
111 dup; |
|
112 invokespecial Method LocalClone$C."<init>":"()V"; |
|
113 invokestatic Method test:"(LLocalClone$I2;)Ljava/lang/Object;"; |
|
114 checkcast class java/lang/String; |
|
115 astore_1; |
|
116 new class java/lang/RuntimeException; |
|
117 dup; |
|
118 ldc String "Expected NSME not thrown"; |
|
119 invokespecial Method java/lang/RuntimeException."<init>":"(Ljava/lang/String;)V"; |
|
120 athrow; |
|
121 endtry t0; |
|
122 catch t0 java/lang/NoSuchMethodError; |
|
123 stack_frame_type stack1; |
|
124 stack_map class java/lang/NoSuchMethodError; |
|
125 astore_1; |
|
126 aload_1; |
|
127 invokevirtual Method java/lang/NoSuchMethodError.toString:"()Ljava/lang/String;"; |
|
128 ldc String "I2.clone"; |
|
129 invokevirtual Method java/lang/String.contains:"(Ljava/lang/CharSequence;)Z"; |
|
130 ifne L47; |
|
131 new class java/lang/RuntimeException; |
|
132 dup; |
|
133 ldc String "Wrong NoSuchMethodError exception thrown"; |
|
134 invokespecial Method java/lang/RuntimeException."<init>":"(Ljava/lang/String;)V"; |
|
135 athrow; |
|
136 L47: stack_frame_type same; |
|
137 return; |
|
138 } |
|
139 |
|
140 static InnerClass C=class LocalClone$C of class LocalClone; |
|
141 static abstract interface InnerClass I2=class LocalClone$I2 of class LocalClone; |
|
142 |
|
143 } // end Class LocalClone |
|
144 |