Thu, 16 Sep 2010 09:56:25 -0700
6985181: Annotations lost from classfile
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Mon Sep 13 11:40:58 2010 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Thu Sep 16 09:56:25 2010 -0700 1.3 @@ -275,6 +275,8 @@ 1.4 env = enter.getTopLevelEnv((JCCompilationUnit)tree); 1.5 break; 1.6 case CLASS: 1.7 + case INTERFACE: 1.8 + case ENUM: 1.9 // System.err.println("CLASS: " + ((JCClassDecl)tree).sym.getSimpleName()); 1.10 env = enter.getClassEnv(((JCClassDecl)tree).sym); 1.11 break;
2.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Mon Sep 13 11:40:58 2010 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Thu Sep 16 09:56:25 2010 -0700 2.3 @@ -114,6 +114,8 @@ 2.4 return p; 2.5 2.6 case CLASS: 2.7 + case INTERFACE: 2.8 + case ENUM: 2.9 p.pos = frame.pos; 2.10 if (((JCClassDecl)frame).extending == tree) { 2.11 p.type = TargetType.CLASS_EXTENDS;
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/T6985181.java Thu Sep 16 09:56:25 2010 -0700 3.3 @@ -0,0 +1,86 @@ 3.4 +/* 3.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 6985181 3.30 + * @summary Annotations lost from classfile 3.31 + */ 3.32 + 3.33 +import java.io.*; 3.34 +import java.util.*; 3.35 + 3.36 +public class T6985181 { 3.37 + public static void main(String... args) throws Exception{ 3.38 + new T6985181().run(); 3.39 + } 3.40 + 3.41 + public void run() throws Exception { 3.42 + String code = "@interface Simple { }\ninterface Test<@Simple T> { }"; 3.43 + 3.44 + File srcFile = writeFile("Test.java", code); 3.45 + File classesDir = new File("classes"); 3.46 + classesDir.mkdirs(); 3.47 + compile("-d", classesDir.getPath(), srcFile.getPath()); 3.48 + String out = javap(new File(classesDir, srcFile.getName().replace(".java", ".class"))); 3.49 + if (!out.contains("RuntimeInvisibleTypeAnnotations")) 3.50 + throw new Exception("RuntimeInvisibleTypeAnnotations not found"); 3.51 + } 3.52 + 3.53 + void compile(String... args) throws Exception { 3.54 + StringWriter sw = new StringWriter(); 3.55 + PrintWriter pw = new PrintWriter(sw); 3.56 + int rc = com.sun.tools.javac.Main.compile(args, pw); 3.57 + pw.close(); 3.58 + String out = sw.toString(); 3.59 + if (out.length() > 0) 3.60 + System.err.println(out); 3.61 + if (rc != 0) 3.62 + throw new Exception("Compilation failed: rc=" + rc); 3.63 + } 3.64 + 3.65 + String javap(File classFile) throws Exception { 3.66 + StringWriter sw = new StringWriter(); 3.67 + PrintWriter pw = new PrintWriter(sw); 3.68 + String[] args = { "-v", classFile.getPath() }; 3.69 + int rc = com.sun.tools.javap.Main.run(args, pw); 3.70 + pw.close(); 3.71 + String out = sw.toString(); 3.72 + if (out.length() > 0) 3.73 + System.err.println(out); 3.74 + if (rc != 0) 3.75 + throw new Exception("javap failed: rc=" + rc); 3.76 + return out; 3.77 + } 3.78 + 3.79 + File writeFile(String path, String body) throws IOException { 3.80 + File f = new File(path); 3.81 + FileWriter out = new FileWriter(f); 3.82 + try { 3.83 + out.write(body); 3.84 + } finally { 3.85 + out.close(); 3.86 + } 3.87 + return f; 3.88 + } 3.89 +}