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>

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

mercurial