Thu, 20 Dec 2012 16:24:18 -0800
8004982: JDK8 source with GPL header errors
Reviewed-by: ohair
mcimadamore@1393 | 1 | /* |
mcimadamore@1393 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@1393 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@1393 | 4 | * |
mcimadamore@1393 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@1393 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@1393 | 7 | * published by the Free Software Foundation. |
mcimadamore@1393 | 8 | * |
mcimadamore@1393 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@1393 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@1393 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@1393 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@1393 | 13 | * accompanied this code). |
mcimadamore@1393 | 14 | * |
mcimadamore@1393 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@1393 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@1393 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@1393 | 18 | * |
mcimadamore@1393 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mcimadamore@1393 | 20 | * or visit www.oracle.com if you need additional information or have any |
mcimadamore@1393 | 21 | * questions. |
mcimadamore@1393 | 22 | */ |
mcimadamore@1393 | 23 | |
mcimadamore@1393 | 24 | /* |
mcimadamore@1393 | 25 | * @test |
mcimadamore@1393 | 26 | * @ignore awaits for VM support |
mcimadamore@1393 | 27 | * @summary check that javac does not generate bridge methods for defaults |
mcimadamore@1393 | 28 | */ |
mcimadamore@1393 | 29 | |
mcimadamore@1393 | 30 | import com.sun.tools.classfile.ClassFile; |
mcimadamore@1393 | 31 | import com.sun.tools.classfile.ConstantPool.*; |
mcimadamore@1393 | 32 | import com.sun.tools.classfile.Method; |
mcimadamore@1393 | 33 | |
mcimadamore@1393 | 34 | import java.io.*; |
mcimadamore@1393 | 35 | |
mcimadamore@1393 | 36 | public class TestNoBridgeOnDefaults { |
mcimadamore@1393 | 37 | |
mcimadamore@1393 | 38 | interface A<X> { |
mcimadamore@1393 | 39 | default <Y> A<X> m(X x, Y y) { return Impl.<X,Y>m1(this, x, y); } |
mcimadamore@1393 | 40 | } |
mcimadamore@1393 | 41 | |
mcimadamore@1393 | 42 | static abstract class B<X> implements A<X> { } |
mcimadamore@1393 | 43 | |
mcimadamore@1393 | 44 | interface C<X> extends A<X> { |
mcimadamore@1393 | 45 | default <Y> C<X> m(X x, Y y) { return Impl.<X,Y>m2(this, x, y); } |
mcimadamore@1393 | 46 | } |
mcimadamore@1393 | 47 | |
mcimadamore@1393 | 48 | static abstract class D<X> extends B<X> implements C<X> { } |
mcimadamore@1393 | 49 | |
mcimadamore@1393 | 50 | static class Impl { |
mcimadamore@1393 | 51 | static <X, Y> A<X> m1(A<X> rec, X x, Y y) { return null; } |
mcimadamore@1393 | 52 | static <X, Y> C<X> m2(C<X> rec, X x, Y y) { return null; } |
mcimadamore@1393 | 53 | } |
mcimadamore@1393 | 54 | |
mcimadamore@1393 | 55 | static final String[] SUBTEST_NAMES = { B.class.getName() + ".class", D.class.getName() + ".class" }; |
mcimadamore@1393 | 56 | static final String TEST_METHOD_NAME = "m"; |
mcimadamore@1393 | 57 | |
mcimadamore@1393 | 58 | public static void main(String... args) throws Exception { |
mcimadamore@1393 | 59 | new TestNoBridgeOnDefaults().run(); |
mcimadamore@1393 | 60 | } |
mcimadamore@1393 | 61 | |
mcimadamore@1393 | 62 | public void run() throws Exception { |
mcimadamore@1393 | 63 | String workDir = System.getProperty("test.classes"); |
mcimadamore@1393 | 64 | for (int i = 0 ; i < SUBTEST_NAMES.length ; i ++) { |
mcimadamore@1393 | 65 | File compiledTest = new File(workDir, SUBTEST_NAMES[i]); |
mcimadamore@1393 | 66 | checkNoBridgeOnDefaults(compiledTest); |
mcimadamore@1393 | 67 | } |
mcimadamore@1393 | 68 | } |
mcimadamore@1393 | 69 | |
mcimadamore@1393 | 70 | void checkNoBridgeOnDefaults(File f) { |
mcimadamore@1393 | 71 | System.err.println("check: " + f); |
mcimadamore@1393 | 72 | try { |
mcimadamore@1393 | 73 | ClassFile cf = ClassFile.read(f); |
mcimadamore@1393 | 74 | for (Method m : cf.methods) { |
mcimadamore@1393 | 75 | String mname = m.getName(cf.constant_pool); |
mcimadamore@1393 | 76 | if (mname.equals(TEST_METHOD_NAME)) { |
mcimadamore@1393 | 77 | throw new Error("unexpected bridge method found " + m); |
mcimadamore@1393 | 78 | } |
mcimadamore@1393 | 79 | } |
mcimadamore@1393 | 80 | } catch (Exception e) { |
mcimadamore@1393 | 81 | e.printStackTrace(); |
mcimadamore@1393 | 82 | throw new Error("error reading " + f +": " + e); |
mcimadamore@1393 | 83 | } |
mcimadamore@1393 | 84 | } |
mcimadamore@1393 | 85 | } |