test/tools/javac/annotations/typeAnnotations/classfile/BridgeShouldHaveNoInteriorAnnotationsTest.java

Fri, 31 Aug 2018 18:43:01 +0100

author
coffeys
date
Fri, 31 Aug 2018 18:43:01 +0100
changeset 3722
4560a907f04f
permissions
-rw-r--r--

8160928: javac incorrectly copies over interior type annotations to bridge method
Reviewed-by: vromero, mcimadamore
Contributed-by: Evgeny Mandrikov <mandrikov@gmail.com>

     1 /*
     2  * Copyright (c) 2018, 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  */
    24 /*
    25  * @test
    26  * @bug 8160928
    27  * @summary javac incorrectly copies over interior type annotations to bridge method
    28  * @library /tools/javac/lib
    29  * @build ToolBox
    30  * @run compile -g BridgeShouldHaveNoInteriorAnnotationsTest.java
    31  * @run main BridgeShouldHaveNoInteriorAnnotationsTest
    32  */
    34 import java.nio.file.Path;
    35 import java.nio.file.Paths;
    36 import java.lang.annotation.ElementType;
    37 import java.lang.annotation.Target;
    38 import java.io.*;
    40 class Pair_8160928<T1, T2> {
    41 }
    43 public class BridgeShouldHaveNoInteriorAnnotationsTest implements java.util.Iterator<Pair_8160928<Object, Object>> {
    45     @Override
    46     public boolean hasNext() {
    47         throw new RuntimeException();
    48     }
    50     @Override
    51     public Pair_8160928<@NonNull Object, Object> next() {
    52         Comparable<@NonNull Object> cble1 = (Comparable<@NonNull Object>) null;
    53         return null;
    54     }
    56     @Override
    57     public void remove() {
    58         throw new RuntimeException();
    59     }
    61     @Target(ElementType.TYPE_USE)
    62     public @interface NonNull {
    63     }
    65     static class OutputExpectedOnceHolder {
    66         public String[] outputs = {
    67             "0: #55(): CAST, offset=0, type_index=0, location=[TYPE_ARGUMENT(0)]",
    68             "1: #55(): LOCAL_VARIABLE, {start_pc=5, length=2, index=1}, location=[TYPE_ARGUMENT(0)]",
    69         };
    70     }
    72     static class OutputExpectedTwiceHolder {
    73         public String[] outputs = {
    74             "0: #55(): METHOD_RETURN, location=[TYPE_ARGUMENT(0)]",
    75         };
    76     }
    78     public static void main(String[] args) throws Exception {
    79         Path classPath = Paths.get(System.getProperty("test.classes"), "BridgeShouldHaveNoInteriorAnnotationsTest.class");
    80         String javapOut = ToolBox.javap(new ToolBox.JavaToolArgs().setAllArgs("-v", "-p", classPath.toString()));
    82         OutputExpectedOnceHolder holder = new OutputExpectedOnceHolder();
    83         for (String s : holder.outputs) {
    84             String newOutput = javapOut.replace(s, "");
    85             if (((javapOut.length() - newOutput.length()) / s.length()) != 1)
    86                 throw new AssertionError("Interior annotations carried over to bridge ?");
    87         }
    89         OutputExpectedTwiceHolder holder2 = new OutputExpectedTwiceHolder();
    90         for (String s : holder2.outputs) {
    91             String newOutput = javapOut.replace(s, "");
    92             if (((javapOut.length() - newOutput.length()) / s.length()) != 2)
    93                 throw new AssertionError("Exterior annotations not properly carried over to bridge");
    94         }
    95     }
    97 }

mercurial