--- old/src/java.base/share/classes/java/lang/reflect/Method.java 2016-06-11 14:21:09.516998679 -0700 +++ new/src/java.base/share/classes/java/lang/reflect/Method.java 2016-06-11 14:21:09.404998684 -0700 @@ -30,6 +30,8 @@ import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.MethodAccessor; import jdk.internal.reflect.Reflection; +import sun.reflect.annotation.ExceptionProxy; +import sun.reflect.annotation.TypeNotPresentExceptionProxy; import sun.reflect.generics.repository.MethodRepository; import sun.reflect.generics.factory.CoreReflectionFactory; import sun.reflect.generics.factory.GenericsFactory; @@ -641,8 +643,13 @@ SharedSecrets.getJavaLangAccess(). getConstantPool(getDeclaringClass()), getDeclaringClass()); - if (result instanceof sun.reflect.annotation.ExceptionProxy) + if (result instanceof ExceptionProxy) { + if (result instanceof TypeNotPresentExceptionProxy) { + TypeNotPresentExceptionProxy proxy = (TypeNotPresentExceptionProxy)result; + throw new TypeNotPresentException(proxy.typeName(), proxy.getCause()); + } throw new AnnotationFormatError("Invalid default: " + this); + } return result; } --- old/src/java.base/share/classes/sun/reflect/annotation/TypeNotPresentExceptionProxy.java 2016-06-11 14:21:09.920998660 -0700 +++ new/src/java.base/share/classes/sun/reflect/annotation/TypeNotPresentExceptionProxy.java 2016-06-11 14:21:09.792998666 -0700 @@ -46,6 +46,14 @@ return new TypeNotPresentException(typeName, cause); } + public String typeName() { + return typeName; + } + + public Throwable getCause() { + return cause; + } + @Override public String toString() { return typeName + ".class /* Warning: type not present! */"; --- old/test/java/lang/annotation/Missing/MissingTest.java 2016-06-11 14:21:10.396998638 -0700 +++ new/test/java/lang/annotation/Missing/MissingTest.java 2016-06-11 14:21:10.236998645 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, 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 @@ -23,15 +23,16 @@ /* * @test - * @bug 6322301 + * @bug 6322301 5041778 * @summary Verify when missing annotation classes cause exceptions * @author Joseph D. Darcy - * @compile MissingTest.java A.java B.java C.java D.java Marker.java Missing.java MissingWrapper.java + * @compile MissingTest.java A.java B.java C.java D.java Marker.java Missing.java MissingWrapper.java MissingDefault.java * @clean Missing * @run main MissingTest */ import java.lang.reflect.*; +import java.lang.annotation.*; /** * This test verifies that a missing annotation class leads to the @@ -112,7 +113,20 @@ } } - public static void main(String argv[]) throws Exception { + private static void testMethodGetDefaultValue(Class clazz) throws Exception{ + Method m = clazz.getMethod("value", (Class[])null); + + try { + System.out.println(m.getDefaultValue()); + throw new RuntimeException("Expected exception not thrown"); + } catch (TypeNotPresentException tnpe) { + ; // Expected + } catch (AnnotationFormatError afe) { + throw new RuntimeException(afe); + } + } + + public static void main(String... args) throws Exception { // Class A has a directly applied annotation whose class is // missing. testAnnotation(A.class, false); @@ -131,5 +145,7 @@ // includes to an annotation class that is missing. testParameterAnnotation(D.class.getDeclaredMethod("method1", Object.class), true); + // The MissingDefault annotation type has a default value of the Missing class. + testMethodGetDefaultValue(MissingDefault.class); } } --- /dev/null 2016-06-01 11:06:58.730877353 -0700 +++ new/test/java/lang/annotation/Missing/MissingDefault.java 2016-06-11 14:21:10.652998626 -0700 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016, 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. + */ + +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * Annotation type with a default value whose class will be missing + * when MissingTest is run. + */ +@Retention(RUNTIME) +public @interface MissingDefault { + Class value()default Missing.class; +}