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

Fri, 03 May 2013 09:56:56 -0700

author
jjg
date
Fri, 03 May 2013 09:56:56 -0700
changeset 1721
abd153854f16
parent 1448
7d34e91f66bb
permissions
-rw-r--r--

8012728: Normalize @ignore comments on langtools tests
Reviewed-by: vromero, mcimadamore

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

mercurial