test/tools/javac/defaultMethods/TestNoBridgeOnDefaults.java

Wed, 07 Nov 2012 17:20:12 -0800

author
jjg
date
Wed, 07 Nov 2012 17:20:12 -0800
changeset 1402
a1dc543483fc
parent 1393
d7d932236fee
child 1415
01c9d4161882
permissions
-rw-r--r--

8003134: CheckResourceKeys issues
Reviewed-by: jjh, bpatel

     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  * @ignore awaits for VM support
    27  * @summary  check that javac does not generate bridge methods for defaults
    28  * @compile -XDallowDefaultMethods TestNoBridgeOnDefaults.java
    29  * @run main TestNoBridgeOnDefaults
    30  */
    32 import com.sun.tools.classfile.ClassFile;
    33 import com.sun.tools.classfile.ConstantPool.*;
    34 import com.sun.tools.classfile.Method;
    36 import java.io.*;
    38 public class TestNoBridgeOnDefaults {
    40     interface A<X> {
    41         default <Y> A<X> m(X x, Y y) { return Impl.<X,Y>m1(this, x, y); }
    42     }
    44     static abstract class B<X> implements A<X> { }
    46     interface C<X> extends A<X> {
    47         default <Y> C<X> m(X x, Y y) { return Impl.<X,Y>m2(this, x, y); }
    48     }
    50     static abstract class D<X> extends B<X> implements C<X> { }
    52     static class Impl {
    53        static <X, Y> A<X> m1(A<X> rec, X x, Y y) { return null; }
    54        static <X, Y> C<X> m2(C<X> rec, X x, Y y) { return null; }
    55     }
    57     static final String[] SUBTEST_NAMES = { B.class.getName() + ".class", D.class.getName() + ".class" };
    58     static final String TEST_METHOD_NAME = "m";
    60     public static void main(String... args) throws Exception {
    61         new TestNoBridgeOnDefaults().run();
    62     }
    64     public void run() throws Exception {
    65         String workDir = System.getProperty("test.classes");
    66         for (int i = 0 ; i < SUBTEST_NAMES.length ; i ++) {
    67             File compiledTest = new File(workDir, SUBTEST_NAMES[i]);
    68             checkNoBridgeOnDefaults(compiledTest);
    69         }
    70     }
    72     void checkNoBridgeOnDefaults(File f) {
    73         System.err.println("check: " + f);
    74         try {
    75             ClassFile cf = ClassFile.read(f);
    76             for (Method m : cf.methods) {
    77                 String mname = m.getName(cf.constant_pool);
    78                 if (mname.equals(TEST_METHOD_NAME)) {
    79                     throw new Error("unexpected bridge method found " + m);
    80                 }
    81             }
    82         } catch (Exception e) {
    83             e.printStackTrace();
    84             throw new Error("error reading " + f +": " + e);
    85         }
    86     }
    87 }

mercurial