1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/BridgeShouldHaveNoInteriorAnnotationsTest.java Fri Aug 31 18:43:01 2018 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +/* 1.5 + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 8160928 1.30 + * @summary javac incorrectly copies over interior type annotations to bridge method 1.31 + * @library /tools/javac/lib 1.32 + * @build ToolBox 1.33 + * @run compile -g BridgeShouldHaveNoInteriorAnnotationsTest.java 1.34 + * @run main BridgeShouldHaveNoInteriorAnnotationsTest 1.35 + */ 1.36 + 1.37 +import java.nio.file.Path; 1.38 +import java.nio.file.Paths; 1.39 +import java.lang.annotation.ElementType; 1.40 +import java.lang.annotation.Target; 1.41 +import java.io.*; 1.42 + 1.43 +class Pair_8160928<T1, T2> { 1.44 +} 1.45 + 1.46 +public class BridgeShouldHaveNoInteriorAnnotationsTest implements java.util.Iterator<Pair_8160928<Object, Object>> { 1.47 + 1.48 + @Override 1.49 + public boolean hasNext() { 1.50 + throw new RuntimeException(); 1.51 + } 1.52 + 1.53 + @Override 1.54 + public Pair_8160928<@NonNull Object, Object> next() { 1.55 + Comparable<@NonNull Object> cble1 = (Comparable<@NonNull Object>) null; 1.56 + return null; 1.57 + } 1.58 + 1.59 + @Override 1.60 + public void remove() { 1.61 + throw new RuntimeException(); 1.62 + } 1.63 + 1.64 + @Target(ElementType.TYPE_USE) 1.65 + public @interface NonNull { 1.66 + } 1.67 + 1.68 + static class OutputExpectedOnceHolder { 1.69 + public String[] outputs = { 1.70 + "0: #55(): CAST, offset=0, type_index=0, location=[TYPE_ARGUMENT(0)]", 1.71 + "1: #55(): LOCAL_VARIABLE, {start_pc=5, length=2, index=1}, location=[TYPE_ARGUMENT(0)]", 1.72 + }; 1.73 + } 1.74 + 1.75 + static class OutputExpectedTwiceHolder { 1.76 + public String[] outputs = { 1.77 + "0: #55(): METHOD_RETURN, location=[TYPE_ARGUMENT(0)]", 1.78 + }; 1.79 + } 1.80 + 1.81 + public static void main(String[] args) throws Exception { 1.82 + Path classPath = Paths.get(System.getProperty("test.classes"), "BridgeShouldHaveNoInteriorAnnotationsTest.class"); 1.83 + String javapOut = ToolBox.javap(new ToolBox.JavaToolArgs().setAllArgs("-v", "-p", classPath.toString())); 1.84 + 1.85 + OutputExpectedOnceHolder holder = new OutputExpectedOnceHolder(); 1.86 + for (String s : holder.outputs) { 1.87 + String newOutput = javapOut.replace(s, ""); 1.88 + if (((javapOut.length() - newOutput.length()) / s.length()) != 1) 1.89 + throw new AssertionError("Interior annotations carried over to bridge ?"); 1.90 + } 1.91 + 1.92 + OutputExpectedTwiceHolder holder2 = new OutputExpectedTwiceHolder(); 1.93 + for (String s : holder2.outputs) { 1.94 + String newOutput = javapOut.replace(s, ""); 1.95 + if (((javapOut.length() - newOutput.length()) / s.length()) != 2) 1.96 + throw new AssertionError("Exterior annotations not properly carried over to bridge"); 1.97 + } 1.98 + } 1.99 + 1.100 +}