< prev index next >
test/java/lang/annotation/Missing/MissingTest.java
Print this page
@@ -1,7 +1,7 @@
/*
- * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -21,19 +21,20 @@
* questions.
*/
/*
* @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
* expected exceptional behavior; a missing directly applied
* annotation is currently ignored but a missing annotation value
@@ -110,11 +111,24 @@
throw new RuntimeException(t);
}
}
}
- 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);
// Class B has a directly applied annotation whose value
@@ -129,7 +143,9 @@
// Class D has a directly applied parameter annotation whose value
// 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);
}
}
< prev index next >