langtools/test/tools/javac/T8042785/FlagsNotCopiedToBridgeMethodTest.java
changeset 24793 bb58a9f1ae10
parent 24792 24452ca131a3
child 24794 22946bb4c27d
equal deleted inserted replaced
24792:24452ca131a3 24793:bb58a9f1ae10
     1 /*
       
     2  * Copyright (c) 2014, 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  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8042785
       
    27  * @summary javac, bridge methods are not getting the flags from the original method
       
    28  * @run main FlagsNotCopiedToBridgeMethodTest
       
    29  */
       
    30 
       
    31 import java.io.BufferedInputStream;
       
    32 import java.nio.file.Files;
       
    33 import java.nio.file.Path;
       
    34 import java.nio.file.Paths;
       
    35 
       
    36 import com.sun.tools.classfile.AccessFlags;
       
    37 import com.sun.tools.classfile.ClassFile;
       
    38 import com.sun.tools.classfile.Method;
       
    39 import com.sun.tools.javac.util.Assert;
       
    40 
       
    41 public class FlagsNotCopiedToBridgeMethodTest {
       
    42 
       
    43     public static void main(String[] args) throws Exception {
       
    44         new FlagsNotCopiedToBridgeMethodTest().run();
       
    45     }
       
    46 
       
    47     void run() throws Exception {
       
    48         checkClassFile(Paths.get(System.getProperty("test.classes"),
       
    49                 this.getClass().getSimpleName() + "$CovariantReturnType.class"));
       
    50         checkClassFile(Paths.get(System.getProperty("test.classes"),
       
    51                 this.getClass().getSimpleName() +
       
    52                 "$CovariantReturnType$VisibilityChange.class"));
       
    53     }
       
    54 
       
    55     void checkClassFile(final Path cfilePath) throws Exception {
       
    56         ClassFile classFile = ClassFile.read(
       
    57                 new BufferedInputStream(Files.newInputStream(cfilePath)));
       
    58         for (Method method : classFile.methods) {
       
    59             if (method.access_flags.is(AccessFlags.ACC_BRIDGE)) {
       
    60                 Assert.check(method.access_flags.is(AccessFlags.ACC_FINAL | AccessFlags.ACC_STRICT),
       
    61                         "bridge method has incorrect flags");
       
    62             }
       
    63         }
       
    64     }
       
    65 
       
    66     abstract class T<A,B> {
       
    67         B m(A a){ return null; }
       
    68     }
       
    69 
       
    70     class CovariantReturnType extends T<Integer, Integer> {
       
    71         strictfp final Integer m(Integer i) {
       
    72             return i;
       
    73         }
       
    74 
       
    75         public class VisibilityChange extends CovariantReturnType {}
       
    76 
       
    77     }
       
    78 
       
    79 }