Mon, 25 Mar 2013 16:55:14 -0700
8010521: jdk8 l10n resource file translation update 2
Reviewed-by: naoto, yhuang
1 /*
2 * Copyright (c) 2011, 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 * @summary check that javac does not generate bridge methods for defaults
27 */
29 import com.sun.tools.classfile.ClassFile;
30 import com.sun.tools.classfile.ConstantPool.*;
31 import com.sun.tools.classfile.Method;
33 import java.io.*;
35 public class TestNoBridgeOnDefaults {
37 interface A<X> {
38 default <Y> A<X> m(X x, Y y) { return Impl.<X,Y>m1(this, x, y); }
39 }
41 static abstract class B<X> implements A<X> { }
43 interface C<X> extends A<X> {
44 default <Y> C<X> m(X x, Y y) { return Impl.<X,Y>m2(this, x, y); }
45 }
47 static abstract class D<X> extends B<X> implements C<X> { }
49 static class Impl {
50 static <X, Y> A<X> m1(A<X> rec, X x, Y y) { return null; }
51 static <X, Y> C<X> m2(C<X> rec, X x, Y y) { return null; }
52 }
54 static final String[] SUBTEST_NAMES = { B.class.getName() + ".class", D.class.getName() + ".class" };
55 static final String TEST_METHOD_NAME = "m";
57 public static void main(String... args) throws Exception {
58 new TestNoBridgeOnDefaults().run();
59 }
61 public void run() throws Exception {
62 String workDir = System.getProperty("test.classes");
63 for (int i = 0 ; i < SUBTEST_NAMES.length ; i ++) {
64 File compiledTest = new File(workDir, SUBTEST_NAMES[i]);
65 checkNoBridgeOnDefaults(compiledTest);
66 }
67 }
69 void checkNoBridgeOnDefaults(File f) {
70 System.err.println("check: " + f);
71 try {
72 ClassFile cf = ClassFile.read(f);
73 for (Method m : cf.methods) {
74 String mname = m.getName(cf.constant_pool);
75 if (mname.equals(TEST_METHOD_NAME)) {
76 throw new Error("unexpected bridge method found " + m);
77 }
78 }
79 } catch (Exception e) {
80 e.printStackTrace();
81 throw new Error("error reading " + f +": " + e);
82 }
83 }
84 }