1 /* 2 * Copyright (c) 2004, 2010, 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 5003916 6704655 6873951 27 * @summary Testing parsing of signatures attributes of nested classes 28 * @author Joseph D. Darcy 29 */ 30 31 import java.lang.reflect.*; 32 import java.lang.annotation.*; 33 import java.util.*; 34 import static java.util.Arrays.*; 35 36 @Classes({"java.util.concurrent.FutureTask", 37 "java.util.concurrent.ConcurrentHashMap$EntryIterator", 38 "java.util.concurrent.ConcurrentHashMap$KeyIterator", 39 "java.util.concurrent.ConcurrentHashMap$ValueIterator", 40 "java.util.AbstractList$ListItr", 41 // "java.util.EnumMap$EntryIterator", 42 // "java.util.EnumMap$KeyIterator", 43 // "java.util.EnumMap$ValueIterator", 44 // "java.util.IdentityHashMap$EntryIterator", 45 // "java.util.IdentityHashMap$KeyIterator", 46 // "java.util.IdentityHashMap$ValueIterator", 47 "java.util.WeakHashMap$EntryIterator", 48 "java.util.WeakHashMap$KeyIterator", 49 "java.util.WeakHashMap$ValueIterator", 50 "java.util.HashMap$EntryIterator", 51 "java.util.HashMap$KeyIterator", 52 "java.util.HashMap$ValueIterator", 53 "java.util.LinkedHashMap$EntryIterator", 54 "java.util.LinkedHashMap$KeyIterator", 55 "java.util.LinkedHashMap$ValueIterator"}) 56 public class Probe { 57 public static void main (String... args) throws Throwable { 58 Classes classesAnnotation = (Probe.class).getAnnotation(Classes.class); 59 List<String> names = 60 new ArrayList<String>(asList(classesAnnotation.value())); 61 62 int errs = 0; 63 for(String name: names) { 64 System.out.println("\nCLASS " + name); 65 Class c = Class.forName(name, false, null); 66 errs += probe(c); 67 System.out.println(errs == 0 ? " ok" : " ERRORS:" + errs); 68 } 69 70 if (errs > 0 ) 71 throw new RuntimeException("Errors during probing."); 72 } 73 74 static int probe (Class c) { 75 int errs = 0; 76 77 try { 78 c.getTypeParameters(); 79 c.getGenericSuperclass(); 80 c.getGenericInterfaces(); 81 } catch (Throwable t) { 82 errs++; 83 System.err.println(t); 84 } 85 86 Field[] fields = c.getDeclaredFields(); 87 if (fields != null) 88 for(Field field: fields) { 89 try { 90 field.getGenericType(); 91 } catch (Throwable t) { 92 errs++; 93 System.err.println("FIELD " + field); 94 System.err.println(t); 95 } 96 } 97 98 Method[] methods = c.getDeclaredMethods(); 99 if (methods != null) 100 for(Method method: methods) { 101 try { 102 method.getTypeParameters(); 103 method.getGenericReturnType(); 104 method.getGenericParameterTypes(); 105 method.getGenericExceptionTypes(); 106 } catch (Throwable t) { 107 errs++; 108 System.err.println("METHOD " + method); 109 System.err.println(t); 110 } 111 } 112 113 Constructor[] ctors = c.getDeclaredConstructors(); 114 if (ctors != null) 115 for(Constructor ctor: ctors) { 116 try { 117 ctor.getTypeParameters(); 118 ctor.getGenericParameterTypes(); 119 ctor.getGenericExceptionTypes(); 120 } catch (Throwable t) { 121 errs++; 122 System.err.println("CONSTRUCTOR " + ctor); 123 System.err.println(t); 124 } 125 } 126 127 return errs; 128 } 129 } 130 131 @Retention(RetentionPolicy.RUNTIME) 132 @interface Classes { 133 String [] value(); // list of classes to probe 134 }