1/* 2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 4979440 27 * @summary Test for signature parsing corner case 28 * @author Joseph D. Darcy 29 */ 30 31import java.lang.reflect.*; 32import java.lang.annotation.*; 33 34/* 35 * Make sure: 36 * 1. getAnnotation can be called directly 37 * 2. getAnnotation can be called reflectively 38 * 3. generic information methods on the Method object for 39 * getAnnotation can be called 40 */ 41 42public class getAnnotationTest { 43 public static void main (String[] args) throws Throwable { 44 // Base level 45 Class c = Class.forName("java.lang.annotation.Retention"); 46 Annotation result = c.getAnnotation(Retention.class); 47 // System.out.println("Base result:" + result); 48 49 // Meta level, invoke Class.getAnnotation reflectively... 50 Class meta_c = c.getClass(); 51 Method meta_getAnnotation = meta_c.getMethod("getAnnotation", 52 (Retention.class).getClass()); 53 54 Object meta_result = meta_getAnnotation.invoke(c, Retention.class); 55 // System.out.println("Meta result:" + meta_result); 56 57 if (!meta_result.equals(result)) { 58 throw new RuntimeException("Base and meta results are not equal."); 59 } 60 61 meta_getAnnotation.getGenericExceptionTypes(); 62 meta_getAnnotation.getGenericParameterTypes(); 63 meta_getAnnotation.getGenericReturnType(); 64 } 65} 66