diff -r 051e64d0816e src/share/classes/com/sun/tools/javac/code/Attribute.java --- a/src/share/classes/com/sun/tools/javac/code/Attribute.java Wed Aug 07 01:32:39 2013 +0200 +++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java Tue Aug 06 20:13:13 2013 -0700 @@ -339,6 +339,14 @@ return v.visitString(toString(), p); } } + + public static class ErroniousClass extends Error { + public Type classType; + public ErroniousClass(Type type, Type classType) { + super(type); + this.classType = classType; + } + } /** A visitor type for dynamic dispatch on the kind of attribute value. */ public static interface Visitor { diff -r 051e64d0816e src/share/classes/com/sun/tools/javac/comp/Annotate.java --- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java Wed Aug 07 01:32:39 2013 +0200 +++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java Tue Aug 06 20:13:13 2013 -0700 @@ -31,12 +31,14 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.code.Type.ErrorType; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; import static com.sun.tools.javac.code.TypeTag.ARRAY; import static com.sun.tools.javac.code.TypeTag.CLASS; import static com.sun.tools.javac.tree.JCTree.Tag.*; +import javax.lang.model.type.TypeKind; /** Enter annotations on symbols. Annotations accumulate in a queue, * which is processed at the top level of any set of recursive calls @@ -333,7 +335,8 @@ if (expected.tsym == syms.classType.tsym) { Type result = attr.attribExpr(tree, env, expected); if (result.isErroneous()) - return new Attribute.Error(expected); + return new Attribute.ErroniousClass(expected, + (((JCFieldAccess) tree).selected).type); if (TreeInfo.name(tree) != names._class) { log.error(tree.pos(), "annotation.value.must.be.class.literal"); return new Attribute.Error(expected); diff -r 051e64d0816e src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java --- a/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java Wed Aug 07 01:32:39 2013 +0200 +++ b/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java Tue Aug 06 20:13:13 2013 -0700 @@ -244,7 +244,10 @@ } public void visitError(Attribute.Error e) { - value = null; // indicates a type mismatch + if (e instanceof Attribute.ErroniousClass) + value = new MirroredTypeExceptionProxy(((Attribute.ErroniousClass)e).classType); + else + value = null; // indicates a type mismatch } diff -r 051e64d0816e test/tools/javac/processing/errors/AssureMirroredTypeException/Processor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/errors/AssureMirroredTypeException/Processor.java Tue Aug 06 20:13:13 2013 -0700 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8019243 + * @summary AnnotationTypeMismatchException instead of MirroredTypeException + * @library /tools/javac/lib + * @build JavacTestingAbstractProcessor Processor + * @compile/fail/ref=Processor.out -classpath . -XDrawDiagnostics -processor Processor Source.java + */ +import java.util.*; +import javax.annotation.processing.*; +import javax.lang.model.element.*; +import javax.lang.model.type.MirroredTypeException; +import javax.lang.model.type.TypeMirror; +import javax.tools.*; + +public class Processor extends JavacTestingAbstractProcessor { + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + for (Element e : roundEnv.getElementsAnnotatedWith(A.class)) { + A rtg = e.getAnnotation(A.class); + if (rtg == null) { + continue; + } + try { + rtg.a(); + } catch (MirroredTypeException ex) { + TypeMirror tm = ex.getTypeMirror(); + messager.printMessage(Diagnostic.Kind.NOTE, ex.toString()); + messager.printMessage(Diagnostic.Kind.NOTE, tm.toString()); + } + } + return true; + } + + @interface A { + Class a(); + } +} diff -r 051e64d0816e test/tools/javac/processing/errors/AssureMirroredTypeException/Processor.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/errors/AssureMirroredTypeException/Processor.out Tue Aug 06 20:13:13 2013 -0700 @@ -0,0 +1,4 @@ +- compiler.note.proc.messager: javax.lang.model.type.MirroredTypeException: Attempt to access Class object for TypeMirror SomeUnknownClass +- compiler.note.proc.messager: SomeUnknownClass +Source.java:1:16: compiler.err.cant.resolve: kindname.class, SomeUnknownClass, , +1 error \ No newline at end of file diff -r 051e64d0816e test/tools/javac/processing/errors/AssureMirroredTypeException/Source.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/errors/AssureMirroredTypeException/Source.java Tue Aug 06 20:13:13 2013 -0700 @@ -0,0 +1,2 @@ +@Processor.A(a=SomeUnknownClass.class) +class Source{}