langtools/test/tools/javac/T8042785/FlagsNotCopiedToBridgeMethodTest.java
author vromero
Fri, 30 May 2014 18:21:05 +0100
changeset 24792 24452ca131a3
permissions -rw-r--r--
8042785: javac, bridge methods are not getting the flags from the original method Reviewed-by: jjg, jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24792
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
     1
/*
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
     4
 *
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
     8
 *
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    13
 * accompanied this code).
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    14
 *
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    18
 *
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    21
 * questions.
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    22
 */
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    23
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    24
/*
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    25
 * @test
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    26
 * @bug 8042785
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    27
 * @summary javac, bridge methods are not getting the flags from the original method
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    28
 * @run main FlagsNotCopiedToBridgeMethodTest
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    29
 */
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    30
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    31
import java.io.BufferedInputStream;
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    32
import java.nio.file.Files;
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    33
import java.nio.file.Path;
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    34
import java.nio.file.Paths;
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    35
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    36
import com.sun.tools.classfile.AccessFlags;
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    37
import com.sun.tools.classfile.ClassFile;
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    38
import com.sun.tools.classfile.Method;
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    39
import com.sun.tools.javac.util.Assert;
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    40
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    41
public class FlagsNotCopiedToBridgeMethodTest {
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    42
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    44
        new FlagsNotCopiedToBridgeMethodTest().run();
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    45
    }
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    46
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    47
    void run() throws Exception {
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    48
        checkClassFile(Paths.get(System.getProperty("test.classes"),
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    49
                this.getClass().getSimpleName() + "$CovariantReturnType.class"));
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    50
        checkClassFile(Paths.get(System.getProperty("test.classes"),
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    51
                this.getClass().getSimpleName() +
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    52
                "$CovariantReturnType$VisibilityChange.class"));
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    53
    }
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    54
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    55
    void checkClassFile(final Path cfilePath) throws Exception {
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    56
        ClassFile classFile = ClassFile.read(
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    57
                new BufferedInputStream(Files.newInputStream(cfilePath)));
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    58
        for (Method method : classFile.methods) {
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    59
            if (method.access_flags.is(AccessFlags.ACC_BRIDGE)) {
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    60
                Assert.check(method.access_flags.is(AccessFlags.ACC_FINAL | AccessFlags.ACC_STRICT),
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    61
                        "bridge method has incorrect flags");
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    62
            }
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    63
        }
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    64
    }
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    65
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    66
    abstract class T<A,B> {
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    67
        B m(A a){ return null; }
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    68
    }
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    69
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    70
    class CovariantReturnType extends T<Integer, Integer> {
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    71
        strictfp final Integer m(Integer i) {
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    72
            return i;
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    73
        }
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    74
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    75
        public class VisibilityChange extends CovariantReturnType {}
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    76
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    77
    }
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    78
24452ca131a3 8042785: javac, bridge methods are not getting the flags from the original method
vromero
parents:
diff changeset
    79
}