langtools/test/tools/javac/annotations/typeAnnotations/classfile/BridgeShouldHaveNoInteriorAnnotationsTest.java
author sadayapalam
Mon, 11 Jul 2016 18:13:42 +0530
changeset 39600 83ea7c12c164
permissions -rw-r--r--
8160928: javac incorrectly copies over interior type annotations to bridge method Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39600
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
     1
/*
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
     4
 *
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
     8
 *
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    13
 * accompanied this code).
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    14
 *
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    18
 *
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    21
 * questions.
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    22
 */
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    23
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    24
/*
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    25
 * @test
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    26
 * @bug 8160928
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    27
 * @summary javac incorrectly copies over interior type annotations to bridge method
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    28
 * @library /tools/lib
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    31
 *          jdk.jdeps/com.sun.tools.javap
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    32
 * @build toolbox.ToolBox toolbox.JavapTask
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    33
 * @run compile -g BridgeShouldHaveNoInteriorAnnotationsTest.java
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    34
 * @run main BridgeShouldHaveNoInteriorAnnotationsTest
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    35
 */
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    36
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    37
import java.nio.file.Path;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    38
import java.nio.file.Paths;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    39
import java.lang.annotation.ElementType;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    40
import java.lang.annotation.Target;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    41
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    42
import toolbox.JavapTask;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    43
import toolbox.Task;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    44
import toolbox.ToolBox;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    45
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    46
class Pair_8160928<T1, T2> {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    47
}
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    48
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    49
public class BridgeShouldHaveNoInteriorAnnotationsTest
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    50
                   implements java.util.Iterator<Pair_8160928<Object, Object>> {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    51
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    52
    @Override
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    53
    public boolean hasNext() {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    54
        throw new RuntimeException();
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    55
    }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    56
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    57
    @Override
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    58
    public Pair_8160928<@NonNull Object, Object> next() {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    59
        Comparable<@NonNull Object> cble1 = (Comparable<@NonNull Object>) null;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    60
        return null;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    61
    }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    62
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    63
    @Override
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    64
    public void remove() {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    65
        throw new UnsupportedOperationException();
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    66
    }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    67
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    68
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    69
    @Target(ElementType.TYPE_USE)
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    70
    public @interface NonNull {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    71
    };
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    72
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    73
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    74
    // Expected output can't be directly encoded into NestedLambdasCastedTest !!!
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    75
    static class OutputExpectedOnceHolder {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    76
        public String[] outputs = {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    77
            "0: #61(): CAST, offset=1, type_index=0, location=[TYPE_ARGUMENT(0)]",
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    78
            "1: #61(): LOCAL_VARIABLE, {start_pc=5, length=2, index=1}, location=[TYPE_ARGUMENT(0)]",
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    79
        };
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    80
    }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    81
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    82
    static class OutputExpectedTwiceHolder {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    83
        public String[] outputs = {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    84
            "0: #61(): METHOD_RETURN, location=[TYPE_ARGUMENT(0)]",
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    85
        };
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    86
    }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    87
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    88
    public static strictfp void main(String args[]) throws Exception {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    89
        ToolBox tb = new ToolBox();
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    90
        Path classPath = Paths.get(ToolBox.testClasses, "BridgeShouldHaveNoInteriorAnnotationsTest.class");
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    91
        String javapOut = new JavapTask(tb)
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    92
                .options("-v", "-p")
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    93
                .classes(classPath.toString())
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    94
                .run()
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    95
                .getOutput(Task.OutputKind.DIRECT);
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    96
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    97
        OutputExpectedOnceHolder holder = new OutputExpectedOnceHolder();
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    98
        for (String s : holder.outputs) {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
    99
            String newOutput = javapOut.replace(s, "");
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   100
            if (((javapOut.length() - newOutput.length()) / s.length()) != 1)
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   101
                throw new AssertionError("Interior annotations carried over to bridge ?");
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   102
        }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   103
        OutputExpectedTwiceHolder holder2 = new OutputExpectedTwiceHolder();
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   104
        for (String s : holder2.outputs) {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   105
            String newOutput = javapOut.replace(s, "");
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   106
            if (((javapOut.length() - newOutput.length()) / s.length()) != 2)
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   107
                throw new AssertionError("Exterior annotations not properly carried over to bridge");
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   108
        }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   109
    }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents:
diff changeset
   110
}