langtools/test/tools/javac/annotations/typeAnnotations/classfile/BridgeShouldHaveNoInteriorAnnotationsTest.java
changeset 39600 83ea7c12c164
equal deleted inserted replaced
39599:3c7da4996d8c 39600:83ea7c12c164
       
     1 /*
       
     2  * Copyright (c) 2016, 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 8160928
       
    27  * @summary javac incorrectly copies over interior type annotations to bridge method
       
    28  * @library /tools/lib
       
    29  * @modules jdk.compiler/com.sun.tools.javac.api
       
    30  *          jdk.compiler/com.sun.tools.javac.main
       
    31  *          jdk.jdeps/com.sun.tools.javap
       
    32  * @build toolbox.ToolBox toolbox.JavapTask
       
    33  * @run compile -g BridgeShouldHaveNoInteriorAnnotationsTest.java
       
    34  * @run main BridgeShouldHaveNoInteriorAnnotationsTest
       
    35  */
       
    36 
       
    37 import java.nio.file.Path;
       
    38 import java.nio.file.Paths;
       
    39 import java.lang.annotation.ElementType;
       
    40 import java.lang.annotation.Target;
       
    41 
       
    42 import toolbox.JavapTask;
       
    43 import toolbox.Task;
       
    44 import toolbox.ToolBox;
       
    45 
       
    46 class Pair_8160928<T1, T2> {
       
    47 }
       
    48 
       
    49 public class BridgeShouldHaveNoInteriorAnnotationsTest
       
    50                    implements java.util.Iterator<Pair_8160928<Object, Object>> {
       
    51 
       
    52     @Override
       
    53     public boolean hasNext() {
       
    54         throw new RuntimeException();
       
    55     }
       
    56 
       
    57     @Override
       
    58     public Pair_8160928<@NonNull Object, Object> next() {
       
    59         Comparable<@NonNull Object> cble1 = (Comparable<@NonNull Object>) null;
       
    60         return null;
       
    61     }
       
    62 
       
    63     @Override
       
    64     public void remove() {
       
    65         throw new UnsupportedOperationException();
       
    66     }
       
    67 
       
    68 
       
    69     @Target(ElementType.TYPE_USE)
       
    70     public @interface NonNull {
       
    71     };
       
    72 
       
    73 
       
    74     // Expected output can't be directly encoded into NestedLambdasCastedTest !!!
       
    75     static class OutputExpectedOnceHolder {
       
    76         public String[] outputs = {
       
    77             "0: #61(): CAST, offset=1, type_index=0, location=[TYPE_ARGUMENT(0)]",
       
    78             "1: #61(): LOCAL_VARIABLE, {start_pc=5, length=2, index=1}, location=[TYPE_ARGUMENT(0)]",
       
    79         };
       
    80     }
       
    81 
       
    82     static class OutputExpectedTwiceHolder {
       
    83         public String[] outputs = {
       
    84             "0: #61(): METHOD_RETURN, location=[TYPE_ARGUMENT(0)]",
       
    85         };
       
    86     }
       
    87 
       
    88     public static strictfp void main(String args[]) throws Exception {
       
    89         ToolBox tb = new ToolBox();
       
    90         Path classPath = Paths.get(ToolBox.testClasses, "BridgeShouldHaveNoInteriorAnnotationsTest.class");
       
    91         String javapOut = new JavapTask(tb)
       
    92                 .options("-v", "-p")
       
    93                 .classes(classPath.toString())
       
    94                 .run()
       
    95                 .getOutput(Task.OutputKind.DIRECT);
       
    96 
       
    97         OutputExpectedOnceHolder holder = new OutputExpectedOnceHolder();
       
    98         for (String s : holder.outputs) {
       
    99             String newOutput = javapOut.replace(s, "");
       
   100             if (((javapOut.length() - newOutput.length()) / s.length()) != 1)
       
   101                 throw new AssertionError("Interior annotations carried over to bridge ?");
       
   102         }
       
   103         OutputExpectedTwiceHolder holder2 = new OutputExpectedTwiceHolder();
       
   104         for (String s : holder2.outputs) {
       
   105             String newOutput = javapOut.replace(s, "");
       
   106             if (((javapOut.length() - newOutput.length()) / s.length()) != 2)
       
   107                 throw new AssertionError("Exterior annotations not properly carried over to bridge");
       
   108         }
       
   109     }
       
   110 }