2
|
1 |
/*
|
|
2 |
* Copyright 2004-2006 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 5003916
|
|
27 |
* @summary Testing parsing of signatures attributes of nested classes
|
|
28 |
* @author Joseph D. Darcy
|
|
29 |
* @compile -source 1.5 Probe.java
|
|
30 |
* @run main Probe
|
|
31 |
*/
|
|
32 |
|
|
33 |
import java.lang.reflect.*;
|
|
34 |
import java.lang.annotation.*;
|
|
35 |
|
|
36 |
@Classes({
|
|
37 |
"java.util.concurrent.FutureTask",
|
|
38 |
"java.util.concurrent.ConcurrentHashMap$EntryIterator",
|
|
39 |
"java.util.concurrent.ConcurrentHashMap$KeyIterator",
|
|
40 |
"java.util.concurrent.ConcurrentHashMap$ValueIterator",
|
|
41 |
"java.util.AbstractList$ListItr",
|
|
42 |
"java.util.EnumMap$EntryIterator",
|
|
43 |
"java.util.EnumMap$KeyIterator",
|
|
44 |
"java.util.EnumMap$ValueIterator",
|
|
45 |
"java.util.IdentityHashMap$EntryIterator",
|
|
46 |
"java.util.IdentityHashMap$KeyIterator",
|
|
47 |
"java.util.IdentityHashMap$ValueIterator",
|
|
48 |
"java.util.WeakHashMap$EntryIterator",
|
|
49 |
"java.util.WeakHashMap$KeyIterator",
|
|
50 |
"java.util.WeakHashMap$ValueIterator",
|
|
51 |
"java.util.TreeMap$EntryIterator",
|
|
52 |
"java.util.TreeMap$KeyIterator",
|
|
53 |
"java.util.TreeMap$ValueIterator",
|
|
54 |
"java.util.HashMap$EntryIterator",
|
|
55 |
"java.util.HashMap$KeyIterator",
|
|
56 |
"java.util.HashMap$ValueIterator",
|
|
57 |
"java.util.LinkedHashMap$EntryIterator",
|
|
58 |
"java.util.LinkedHashMap$KeyIterator",
|
|
59 |
"java.util.LinkedHashMap$ValueIterator",
|
|
60 |
"javax.crypto.SunJCE_c",
|
|
61 |
"javax.crypto.SunJCE_e",
|
|
62 |
"javax.crypto.SunJCE_f",
|
|
63 |
"javax.crypto.SunJCE_j",
|
|
64 |
"javax.crypto.SunJCE_k",
|
|
65 |
"javax.crypto.SunJCE_l"
|
|
66 |
})
|
|
67 |
public class Probe {
|
|
68 |
public static void main (String[] args) throws Throwable {
|
|
69 |
String [] names = (Probe.class).getAnnotation(Classes.class).value();
|
|
70 |
|
|
71 |
int errs = 0;
|
|
72 |
for(String name: names) {
|
|
73 |
System.out.println("\nCLASS " + name);
|
|
74 |
Class c = Class.forName(name, false, null);
|
|
75 |
errs += probe(c);
|
|
76 |
System.out.println(errs == 0 ? " ok" : " ERRORS:" + errs);
|
|
77 |
}
|
|
78 |
|
|
79 |
if (errs > 0 )
|
|
80 |
throw new RuntimeException("Errors during probing.");
|
|
81 |
}
|
|
82 |
|
|
83 |
static int probe (Class c) {
|
|
84 |
int errs = 0;
|
|
85 |
|
|
86 |
try {
|
|
87 |
c.getTypeParameters();
|
|
88 |
c.getGenericSuperclass();
|
|
89 |
c.getGenericInterfaces();
|
|
90 |
} catch (Throwable t) {
|
|
91 |
errs++;
|
|
92 |
System.err.println(t);
|
|
93 |
}
|
|
94 |
|
|
95 |
Field[] fields = c.getDeclaredFields();
|
|
96 |
if (fields != null)
|
|
97 |
for(Field field: fields) {
|
|
98 |
try {
|
|
99 |
field.getGenericType();
|
|
100 |
} catch (Throwable t) {
|
|
101 |
errs++;
|
|
102 |
System.err.println("FIELD " + field);
|
|
103 |
System.err.println(t);
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
Method[] methods = c.getDeclaredMethods();
|
|
108 |
if (methods != null)
|
|
109 |
for(Method method: methods) {
|
|
110 |
try {
|
|
111 |
method.getTypeParameters();
|
|
112 |
method.getGenericReturnType();
|
|
113 |
method.getGenericParameterTypes();
|
|
114 |
method.getGenericExceptionTypes();
|
|
115 |
} catch (Throwable t) {
|
|
116 |
errs++;
|
|
117 |
System.err.println("METHOD " + method);
|
|
118 |
System.err.println(t);
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
Constructor[] ctors = c.getDeclaredConstructors();
|
|
123 |
if (ctors != null)
|
|
124 |
for(Constructor ctor: ctors) {
|
|
125 |
try {
|
|
126 |
ctor.getTypeParameters();
|
|
127 |
ctor.getGenericParameterTypes();
|
|
128 |
ctor.getGenericExceptionTypes();
|
|
129 |
} catch (Throwable t) {
|
|
130 |
errs++;
|
|
131 |
System.err.println("CONSTRUCTOR " + ctor);
|
|
132 |
System.err.println(t);
|
|
133 |
}
|
|
134 |
}
|
|
135 |
|
|
136 |
return errs;
|
|
137 |
}
|
|
138 |
}
|
|
139 |
|
|
140 |
@Retention(RetentionPolicy.RUNTIME)
|
|
141 |
@interface Classes {
|
|
142 |
String [] value(); // list of classes to probe
|
|
143 |
}
|