Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
1 /*
2 * Copyright (c) 2011, 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.
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 */
24 /*
25 * @test
26 * @bug 7192246
27 * @summary check that javac does not generate bridge methods for defaults
28 */
30 import com.sun.tools.classfile.ClassFile;
31 import com.sun.tools.classfile.ConstantPool.*;
32 import com.sun.tools.classfile.Method;
34 import java.io.*;
36 public class TestNoBridgeOnDefaults {
38 interface A<X> {
39 default <Y> A<X> m(X x, Y y) { return Impl.<X,Y>m1(this, x, y); }
40 }
42 static abstract class B<X> implements A<X> { }
44 interface C<X> extends A<X> {
45 default <Y> C<X> m(X x, Y y) { return Impl.<X,Y>m2(this, x, y); }
46 }
48 static abstract class D<X> extends B<X> implements C<X> { }
50 static class Impl {
51 static <X, Y> A<X> m1(A<X> rec, X x, Y y) { return null; }
52 static <X, Y> C<X> m2(C<X> rec, X x, Y y) { return null; }
53 }
55 static final String[] SUBTEST_NAMES = { B.class.getName() + ".class", D.class.getName() + ".class" };
56 static final String TEST_METHOD_NAME = "m";
58 public static void main(String... args) throws Exception {
59 new TestNoBridgeOnDefaults().run();
60 }
62 public void run() throws Exception {
63 String workDir = System.getProperty("test.classes");
64 for (int i = 0 ; i < SUBTEST_NAMES.length ; i ++) {
65 File compiledTest = new File(workDir, SUBTEST_NAMES[i]);
66 checkNoBridgeOnDefaults(compiledTest);
67 }
68 }
70 void checkNoBridgeOnDefaults(File f) {
71 System.err.println("check: " + f);
72 try {
73 ClassFile cf = ClassFile.read(f);
74 for (Method m : cf.methods) {
75 String mname = m.getName(cf.constant_pool);
76 if (mname.equals(TEST_METHOD_NAME)) {
77 throw new Error("unexpected bridge method found " + m);
78 }
79 }
80 } catch (Exception e) {
81 e.printStackTrace();
82 throw new Error("error reading " + f +": " + e);
83 }
84 }
85 }