test/tools/javac/defaultMethods/defaultMethodExecution/DefaultMethodRegressionTests.java

changeset 1966
b59a0b4675c9
parent 1721
abd153854f16
equal deleted inserted replaced
1938:dd4a00c220c6 1966:b59a0b4675c9
1 /*
2 * Copyright (c) 2012, 2013, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 /**
27 * @test
28 * @ignore 8007517: DefaultMethodRegressionTests.java fail in TL
29 * @bug 8003639
30 * @summary convert lambda testng tests to jtreg and add them
31 * @run testng DefaultMethodRegressionTests
32 */
33
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37 import org.testng.annotations.Test;
38
39 import static org.testng.Assert.*;
40
41 /**
42 * This set of classes/interfaces (K/I/C) is specially designed to expose a
43 * bug in the JVM where it did not find some overloaded methods in some
44 * specific situations. (fixed by hotspot changeset ffb9316fd9ed)
45 */
46 interface K {
47 int bbb(Long l);
48 }
49
50 interface I extends K {
51 default void aaa() {}
52 default void aab() {}
53 default void aac() {}
54
55 default int bbb(Integer i) { return 22; }
56 default int bbb(Float f) { return 33; }
57 default int bbb(Long l) { return 44; }
58 default int bbb(Double d) { return 55; }
59 default int bbb(String s) { return 66; }
60
61 default void caa() {}
62 default void cab() {}
63 default void cac() {}
64 }
65
66 class C implements I {}
67
68 public class DefaultMethodRegressionTests {
69
70 @Test(groups = "vm")
71 public void testLostOverloadedMethod() {
72 C c = new C();
73 assertEquals(c.bbb(new Integer(1)), 22);
74 assertEquals(c.bbb(new Float(1.1)), 33);
75 assertEquals(c.bbb(new Long(1L)), 44);
76 assertEquals(c.bbb(new Double(0.01)), 55);
77 assertEquals(c.bbb(new String("")), 66);
78 }
79
80 // Test to ensure that the inference verifier accepts older classfiles
81 // with classes that implement interfaces with defaults.
82 @Test(groups = "vm")
83 public void testInferenceVerifier() {
84 // interface I { int m() default { return 99; } }
85 byte I_bytes[] = {
86 (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x33,
87 0x00, 0x08, 0x07, 0x00, 0x06, 0x07, 0x00, 0x07,
88 0x01, 0x00, 0x03, 0x66, 0x6f, 0x6f, 0x01, 0x00,
89 0x03, 0x28, 0x29, 0x49, 0x01, 0x00, 0x04, 0x43,
90 0x6f, 0x64, 0x65, 0x01, 0x00, 0x01, 0x49, 0x01,
91 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c,
92 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65,
93 0x63, 0x74, 0x06, 0x00, 0x00, 0x01, 0x00, 0x02,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01,
95 0x00, 0x03, 0x00, 0x04, 0x00, 0x01, 0x00, 0x05,
96 0x00, 0x00, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x01,
97 0x00, 0x00, 0x00, 0x03, 0x10, 0x63, (byte)0xac, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00
99 };
100 // public class C implements I {} /* -target 1.5 */
101 byte C_bytes[] = {
102 (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x31,
103 0x00, 0x0c, 0x0a, 0x00, 0x03, 0x00, 0x08, 0x07,
104 0x00, 0x09, 0x07, 0x00, 0x0a, 0x07, 0x00, 0x0b,
105 0x01, 0x00, 0x06, 0x3c, 0x69, 0x6e, 0x69, 0x74,
106 0x3e, 0x01, 0x00, 0x03, 0x28, 0x29, 0x56, 0x01,
107 0x00, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x0c, 0x00,
108 0x05, 0x00, 0x06, 0x01, 0x00, 0x01, 0x43, 0x01,
109 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c,
110 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65,
111 0x63, 0x74, 0x01, 0x00, 0x01, 0x49, 0x00, 0x21,
112 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04,
113 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x05,
114 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00,
115 0x00, 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
116 0x00, 0x05, 0x2a, (byte)0xb7, 0x00, 0x01, (byte)0xb1, 0x00,
117 0x00, 0x00, 0x00, 0x00, 0x00
118 };
119
120 ClassLoader cl = new ClassLoader() {
121 protected Class<?> findClass(String name) {
122 if (name.equals("I")) {
123 return defineClass("I", I_bytes, 0, I_bytes.length);
124 } else if (name.equals("C")) {
125 return defineClass("C", C_bytes, 0, C_bytes.length);
126 } else {
127 return null;
128 }
129 }
130 };
131 try {
132 Class.forName("C", true, cl);
133 } catch (Exception e) {
134 // unmodified verifier will throw VerifyError
135 fail("No exception should be thrown");
136 }
137 }
138 }

mercurial