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 a default method named clone() does not get masked by 29 * java.lang.Object.clone(). 30 * @compile DefaultClone.jasm 31 * @run main DefaultClone 32 */ 33 34 // The below .jasm code implements the following java code: 35 // 36 // public class DefaultClone { 37 // 38 // interface I1 { 39 // default Object clone() { 40 // return "In I1's clone()"; 41 // } 42 // } 43 // 44 // 45 // interface I2 extends I1 { } 46 // 47 // 48 // static class C implements I2 { 49 // public Object clone() { 50 // return "In C's clone()"; 51 // } 52 // } 53 // 54 // 55 // static Object test(I2 i) { return i.clone(); } 56 // 57 // public static void main(String[] args) { 58 // String s = (String)test(new C()); 59 // if (!s.equals("In C's clone()")) { 60 // throw new RuntimeException("Wrong clone() called"); 61 // } 62 // } 63 // } 64 65 66 interface DefaultClone$I1 version 53:0 { 67 68 public Method clone:"()Ljava/lang/Object;" stack 1 locals 1 { 69 ldc String "In I1\'s clone()"; 70 areturn; 71 } 72 73 static abstract interface InnerClass I1=class DefaultClone$I1 of class DefaultClone; 74 75 } // end Class DefaultClone$I1 76 77 78 79 interface DefaultClone$I2 implements DefaultClone$I1 version 53:0 { 80 81 static abstract interface InnerClass I2=class DefaultClone$I2 of class DefaultClone; 82 static abstract interface InnerClass I1=class DefaultClone$I1 of class DefaultClone; 83 84 } // end Class DefaultClone$I2 85 86 87 super class DefaultClone$C implements DefaultClone$I2 version 53:0 { 88 89 Method "<init>":"()V" stack 1 locals 1 { 90 aload_0; 91 invokespecial Method java/lang/Object."<init>":"()V"; 92 return; 93 } 94 95 public Method clone:"()Ljava/lang/Object;" stack 1 locals 1 { 96 ldc String "In C\'s clone()"; 97 areturn; 98 } 99 100 static InnerClass C=class DefaultClone$C of class DefaultClone; 101 static abstract interface InnerClass I2=class DefaultClone$I2 of class DefaultClone; 102 103 } // end Class DefaultClone$C 104 105 106 super public class DefaultClone version 53:0 { 107 108 public Method "<init>":"()V" stack 1 locals 1 { 109 aload_0; 110 invokespecial Method java/lang/Object."<init>":"()V"; 111 return; 112 } 113 114 static Method test:"(LDefaultClone$I2;)Ljava/lang/Object;" stack 1 locals 1 { 115 aload_0; 116 invokeinterface InterfaceMethod DefaultClone$I2.clone:"()Ljava/lang/Object;", 1; 117 areturn; 118 } 119 120 public static Method main:"([Ljava/lang/String;)V" stack 3 locals 2 { 121 new class DefaultClone$C; 122 dup; 123 invokespecial Method DefaultClone$C."<init>":"()V"; 124 invokestatic Method test:"(LDefaultClone$I2;)Ljava/lang/Object;"; 125 checkcast class java/lang/String; 126 astore_1; 127 aload_1; 128 ldc String "In C\'s clone()"; 129 invokevirtual Method java/lang/String.equals:"(Ljava/lang/Object;)Z"; 130 ifne L33; 131 new class java/lang/RuntimeException; 132 dup; 133 ldc String "Wrong clone() called"; 134 invokespecial Method java/lang/RuntimeException."<init>":"(Ljava/lang/String;)V"; 135 athrow; 136 L33: stack_frame_type append; 137 locals_map class java/lang/String; 138 return; 139 } 140 141 static InnerClass C=class DefaultClone$C of class DefaultClone; 142 static abstract interface InnerClass I2=class DefaultClone$I2 of class DefaultClone; 143 static abstract interface InnerClass I1=class DefaultClone$I1 of class DefaultClone; 144 145 } // end Class DefaultClone