Probe.java revision 842
0N/A/*
0N/A * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 5003916 6704655
0N/A * @summary Testing parsing of signatures attributes of nested classes
0N/A * @author Joseph D. Darcy
0N/A * @compile -source 1.5 Probe.java
0N/A * @run main Probe
0N/A */
0N/A
0N/Aimport java.lang.reflect.*;
0N/Aimport java.lang.annotation.*;
0N/Aimport java.util.*;
0N/Aimport static java.util.Arrays.*;
0N/A
0N/A@Classes(value={
0N/A "java.util.concurrent.FutureTask",
0N/A "java.util.concurrent.ConcurrentHashMap$EntryIterator",
0N/A "java.util.concurrent.ConcurrentHashMap$KeyIterator",
0N/A "java.util.concurrent.ConcurrentHashMap$ValueIterator",
0N/A "java.util.AbstractList$ListItr",
0N/A "java.util.EnumMap$EntryIterator",
0N/A "java.util.EnumMap$KeyIterator",
0N/A "java.util.EnumMap$ValueIterator",
0N/A "java.util.IdentityHashMap$EntryIterator",
0N/A "java.util.IdentityHashMap$KeyIterator",
0N/A "java.util.IdentityHashMap$ValueIterator",
0N/A "java.util.WeakHashMap$EntryIterator",
0N/A "java.util.WeakHashMap$KeyIterator",
0N/A "java.util.WeakHashMap$ValueIterator",
0N/A "java.util.TreeMap$EntryIterator",
0N/A "java.util.TreeMap$KeyIterator",
0N/A "java.util.TreeMap$ValueIterator",
0N/A "java.util.HashMap$EntryIterator",
0N/A "java.util.HashMap$KeyIterator",
0N/A "java.util.HashMap$ValueIterator",
0N/A "java.util.LinkedHashMap$EntryIterator",
0N/A "java.util.LinkedHashMap$KeyIterator",
0N/A "java.util.LinkedHashMap$ValueIterator"
0N/A },
0N/A sunClasses={
0N/A "javax.crypto.SunJCE_c",
0N/A "javax.crypto.SunJCE_e",
0N/A "javax.crypto.SunJCE_f",
0N/A "javax.crypto.SunJCE_j",
0N/A "javax.crypto.SunJCE_k",
0N/A "javax.crypto.SunJCE_l"
0N/A })
0N/Apublic class Probe {
0N/A public static void main (String[] args) throws Throwable {
0N/A Classes classesAnnotation = (Probe.class).getAnnotation(Classes.class);
0N/A List<String> names =
0N/A new ArrayList<String>(asList(classesAnnotation.value()));
0N/A
0N/A if (System.getProperty("java.runtime.name").startsWith("Java(TM)")) {
0N/A // Sun production JDK; test crypto classes too
for(String name: classesAnnotation.sunClasses())
names.add(name);
}
int errs = 0;
for(String name: names) {
System.out.println("\nCLASS " + name);
Class c = Class.forName(name, false, null);
errs += probe(c);
System.out.println(errs == 0 ? " ok" : " ERRORS:" + errs);
}
if (errs > 0 )
throw new RuntimeException("Errors during probing.");
}
static int probe (Class c) {
int errs = 0;
try {
c.getTypeParameters();
c.getGenericSuperclass();
c.getGenericInterfaces();
} catch (Throwable t) {
errs++;
System.err.println(t);
}
Field[] fields = c.getDeclaredFields();
if (fields != null)
for(Field field: fields) {
try {
field.getGenericType();
} catch (Throwable t) {
errs++;
System.err.println("FIELD " + field);
System.err.println(t);
}
}
Method[] methods = c.getDeclaredMethods();
if (methods != null)
for(Method method: methods) {
try {
method.getTypeParameters();
method.getGenericReturnType();
method.getGenericParameterTypes();
method.getGenericExceptionTypes();
} catch (Throwable t) {
errs++;
System.err.println("METHOD " + method);
System.err.println(t);
}
}
Constructor[] ctors = c.getDeclaredConstructors();
if (ctors != null)
for(Constructor ctor: ctors) {
try {
ctor.getTypeParameters();
ctor.getGenericParameterTypes();
ctor.getGenericExceptionTypes();
} catch (Throwable t) {
errs++;
System.err.println("CONSTRUCTOR " + ctor);
System.err.println(t);
}
}
return errs;
}
}
@Retention(RetentionPolicy.RUNTIME)
@interface Classes {
String [] value(); // list of classes to probe
String [] sunClasses(); // list of Sun-production JDK specific classes to probe
}