< prev index next >

test/java/lang/annotation/AnnotationVerifier.java

Print this page

        

@@ -25,12 +25,18 @@
 
 /*
  * Create class file using ASM, slightly modified the ASMifier output
  */
 
-import sun.reflect.annotation.AnnotationType;
+import java.lang.annotation.Annotation;
 import java.lang.annotation.AnnotationFormatError;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.Arrays;
+
 import org.testng.annotations.*;
 
 /*
  * @test
  * @bug 8158510

@@ -43,21 +49,41 @@
  * @run testng AnnotationVerifier
  */
 
 public class AnnotationVerifier {
 
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(ElementType.TYPE)
+    @interface GoodAnnotation {}
+
     @AnnotationWithParameter
     @AnnotationWithVoidReturn
-    static class BadAnnotation {
+    @GoodAnnotation
+    static class AnnotationHolder {
+    }
+
+    @Test(expectedExceptions = AnnotationFormatError.class)
+    public void annotationWithParameter() {
+        Annotation ann = AnnotationHolder.class.getAnnotation(AnnotationWithParameter.class);
+        System.out.println(ann);
     }
 
-    @Test
-    @ExpectedExceptions(IllegalArgumentException.class)
-    public void annotationValidationIAE() {
-        AnnotationType.getInstance(AnnotationWithParameter.class);
+    @Test(expectedExceptions = AnnotationFormatError.class)
+    public void annotationWithVoidReturn() {
+        Annotation ann = AnnotationHolder.class.getAnnotation(AnnotationWithVoidReturn.class);
+        System.out.println(ann);
+   }
+
+    @Test(expectedExceptions = AnnotationFormatError.class)
+    public void badAnnotations() {
+        Annotation[] anns = AnnotationHolder.class.getAnnotations();
+        System.out.println(Arrays.toString(anns));
     }
 
     @Test(expectedExceptions = AnnotationFormatError.class)
-    public void annotationValidationAFE() {
-        BadAnnotation.class.getAnnotation(AnnotationWithVoidReturn.class);
+    public void goodAnnotation() {
+        // this annotation is good, but since we parse all annotations in bulk,
+        // the exception is thrown because of other bad annotations...
+        Annotation ann = AnnotationHolder.class.getAnnotation(GoodAnnotation.class);
+        System.out.println(ann);
     }
 }
< prev index next >