Thu, 16 Sep 2010 09:56:25 -0700
6985181: Annotations lost from classfile
Reviewed-by: mcimadamore
jjg@682 | 1 | /* |
jjg@682 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@682 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@682 | 4 | * |
jjg@682 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@682 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@682 | 7 | * published by the Free Software Foundation. |
jjg@682 | 8 | * |
jjg@682 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@682 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@682 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@682 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@682 | 13 | * accompanied this code). |
jjg@682 | 14 | * |
jjg@682 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@682 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@682 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@682 | 18 | * |
jjg@682 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@682 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@682 | 21 | * questions. |
jjg@682 | 22 | */ |
jjg@682 | 23 | |
jjg@682 | 24 | /* |
jjg@682 | 25 | * @test |
jjg@682 | 26 | * @bug 6985181 |
jjg@682 | 27 | * @summary Annotations lost from classfile |
jjg@682 | 28 | */ |
jjg@682 | 29 | |
jjg@682 | 30 | import java.io.*; |
jjg@682 | 31 | import java.util.*; |
jjg@682 | 32 | |
jjg@682 | 33 | public class T6985181 { |
jjg@682 | 34 | public static void main(String... args) throws Exception{ |
jjg@682 | 35 | new T6985181().run(); |
jjg@682 | 36 | } |
jjg@682 | 37 | |
jjg@682 | 38 | public void run() throws Exception { |
jjg@682 | 39 | String code = "@interface Simple { }\ninterface Test<@Simple T> { }"; |
jjg@682 | 40 | |
jjg@682 | 41 | File srcFile = writeFile("Test.java", code); |
jjg@682 | 42 | File classesDir = new File("classes"); |
jjg@682 | 43 | classesDir.mkdirs(); |
jjg@682 | 44 | compile("-d", classesDir.getPath(), srcFile.getPath()); |
jjg@682 | 45 | String out = javap(new File(classesDir, srcFile.getName().replace(".java", ".class"))); |
jjg@682 | 46 | if (!out.contains("RuntimeInvisibleTypeAnnotations")) |
jjg@682 | 47 | throw new Exception("RuntimeInvisibleTypeAnnotations not found"); |
jjg@682 | 48 | } |
jjg@682 | 49 | |
jjg@682 | 50 | void compile(String... args) throws Exception { |
jjg@682 | 51 | StringWriter sw = new StringWriter(); |
jjg@682 | 52 | PrintWriter pw = new PrintWriter(sw); |
jjg@682 | 53 | int rc = com.sun.tools.javac.Main.compile(args, pw); |
jjg@682 | 54 | pw.close(); |
jjg@682 | 55 | String out = sw.toString(); |
jjg@682 | 56 | if (out.length() > 0) |
jjg@682 | 57 | System.err.println(out); |
jjg@682 | 58 | if (rc != 0) |
jjg@682 | 59 | throw new Exception("Compilation failed: rc=" + rc); |
jjg@682 | 60 | } |
jjg@682 | 61 | |
jjg@682 | 62 | String javap(File classFile) throws Exception { |
jjg@682 | 63 | StringWriter sw = new StringWriter(); |
jjg@682 | 64 | PrintWriter pw = new PrintWriter(sw); |
jjg@682 | 65 | String[] args = { "-v", classFile.getPath() }; |
jjg@682 | 66 | int rc = com.sun.tools.javap.Main.run(args, pw); |
jjg@682 | 67 | pw.close(); |
jjg@682 | 68 | String out = sw.toString(); |
jjg@682 | 69 | if (out.length() > 0) |
jjg@682 | 70 | System.err.println(out); |
jjg@682 | 71 | if (rc != 0) |
jjg@682 | 72 | throw new Exception("javap failed: rc=" + rc); |
jjg@682 | 73 | return out; |
jjg@682 | 74 | } |
jjg@682 | 75 | |
jjg@682 | 76 | File writeFile(String path, String body) throws IOException { |
jjg@682 | 77 | File f = new File(path); |
jjg@682 | 78 | FileWriter out = new FileWriter(f); |
jjg@682 | 79 | try { |
jjg@682 | 80 | out.write(body); |
jjg@682 | 81 | } finally { |
jjg@682 | 82 | out.close(); |
jjg@682 | 83 | } |
jjg@682 | 84 | return f; |
jjg@682 | 85 | } |
jjg@682 | 86 | } |