Tue, 08 Sep 2009 14:08:26 -0700
6709246: ClassCastException in javadoc
Reviewed-by: jjg
Contributed-by: ahe@google.com
1.1 --- a/src/share/classes/com/sun/tools/javadoc/AnnotationDescImpl.java Tue Sep 08 13:53:10 2009 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javadoc/AnnotationDescImpl.java Tue Sep 08 14:08:26 2009 -0700 1.3 @@ -60,7 +60,12 @@ 1.4 */ 1.5 public AnnotationTypeDoc annotationType() { 1.6 ClassSymbol atsym = (ClassSymbol)annotation.type.tsym; 1.7 - return (AnnotationTypeDoc)env.getClassDoc(atsym); 1.8 + if (annotation.type.isErroneous()) { 1.9 + env.warning(null, "javadoc.class_not_found", annotation.type.toString()); 1.10 + return new AnnotationTypeDocImpl(env, atsym); 1.11 + } else { 1.12 + return (AnnotationTypeDoc)env.getClassDoc(atsym); 1.13 + } 1.14 } 1.15 1.16 /**
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javadoc/annotations/missing/Main.java Tue Sep 08 14:08:26 2009 -0700 2.3 @@ -0,0 +1,52 @@ 2.4 +/* 2.5 + * Copyright 2009 Google, Inc. All Rights Reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 + * have any questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 6709246 2.30 + * @summary Class-cast exception when annotation type is missing. 2.31 + * @library ../../lib 2.32 + */ 2.33 + 2.34 +import java.io.IOException; 2.35 +import com.sun.javadoc.RootDoc; 2.36 +import com.sun.javadoc.ClassDoc; 2.37 +import com.sun.javadoc.AnnotationDesc; 2.38 + 2.39 +public class Main extends Tester.Doclet { 2.40 + 2.41 + private static final Tester tester = new Tester("Main", "somepackage"); 2.42 + 2.43 + public static void main(String... args) throws Exception { 2.44 + tester.run(); 2.45 + } 2.46 + 2.47 + public static boolean start(RootDoc root) { 2.48 + for (ClassDoc d : root.classes()) { 2.49 + for (AnnotationDesc a : d.annotations()) { 2.50 + System.out.println(a.annotationType()); 2.51 + } 2.52 + } 2.53 + return true; 2.54 + } 2.55 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javadoc/annotations/missing/somepackage/MissingAnnotationClass.java Tue Sep 08 14:08:26 2009 -0700 3.3 @@ -0,0 +1,31 @@ 3.4 +/* 3.5 + * Copyright 2009 Google, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 3.24 + * have any questions. 3.25 + */ 3.26 + 3.27 +package somepackage; 3.28 + 3.29 +/** 3.30 + * This class has an annotation which is not available. 3.31 + */ 3.32 +@NoSuchAnnotation 3.33 +public class MissingAnnotationClass { 3.34 +}