@@ -17,20 +17,20 @@ public class Reflector {
17
17
18
18
private static boolean classCacheEnabled = true ;
19
19
private static final String [] EMPTY_STRING_ARRAY = new String [0 ];
20
- private static final Map <Class , Reflector > REFLECTOR_MAP = Collections .synchronizedMap (new HashMap <Class , Reflector >());
20
+ private static final Map <Class <?> , Reflector > REFLECTOR_MAP = Collections .synchronizedMap (new HashMap <Class <?> , Reflector >());
21
21
22
- private Class type ;
22
+ private Class <?> type ;
23
23
private String [] readablePropertyNames = EMPTY_STRING_ARRAY ;
24
24
private String [] writeablePropertyNames = EMPTY_STRING_ARRAY ;
25
25
private Map <String , Invoker > setMethods = new HashMap <String , Invoker >();
26
26
private Map <String , Invoker > getMethods = new HashMap <String , Invoker >();
27
- private Map <String , Class > setTypes = new HashMap <String , Class >();
28
- private Map <String , Class > getTypes = new HashMap <String , Class >();
29
- private Constructor defaultConstructor ;
27
+ private Map <String , Class <?>> setTypes = new HashMap <String , Class <?> >();
28
+ private Map <String , Class <?>> getTypes = new HashMap <String , Class <?> >();
29
+ private Constructor <?> defaultConstructor ;
30
30
31
31
private Map <String , String > caseInsensitivePropertyMap = new HashMap <String , String >();
32
32
33
- private Reflector (Class clazz ) {
33
+ private Reflector (Class <?> clazz ) {
34
34
type = clazz ;
35
35
addDefaultConstructor (clazz );
36
36
addGetMethods (clazz );
@@ -46,9 +46,9 @@ private Reflector(Class clazz) {
46
46
}
47
47
}
48
48
49
- private void addDefaultConstructor (Class clazz ) {
50
- Constructor [] consts = clazz .getDeclaredConstructors ();
51
- for (Constructor constructor : consts ) {
49
+ private void addDefaultConstructor (Class <?> clazz ) {
50
+ Constructor <?> [] consts = clazz .getDeclaredConstructors ();
51
+ for (Constructor <?> constructor : consts ) {
52
52
if (constructor .getParameterTypes ().length == 0 ) {
53
53
if (canAccessPrivateMethods ()) {
54
54
try {
@@ -64,7 +64,7 @@ private void addDefaultConstructor(Class clazz) {
64
64
}
65
65
}
66
66
67
- private void addGetMethods (Class cls ) {
67
+ private void addGetMethods (Class <?> cls ) {
68
68
Method [] methods = getClassMethods (cls );
69
69
for (Method method : methods ) {
70
70
String name = method .getName ();
@@ -89,7 +89,7 @@ private void addGetMethod(String name, Method method) {
89
89
}
90
90
}
91
91
92
- private void addSetMethods (Class cls ) {
92
+ private void addSetMethods (Class <?> cls ) {
93
93
Map <String , List <Method >> conflictingSetters = new HashMap <String , List <Method >>();
94
94
Method [] methods = getClassMethods (cls );
95
95
for (Method method : methods ) {
@@ -120,7 +120,7 @@ private void resolveSetterConflicts(Map<String, List<Method>> conflictingSetters
120
120
if (setters .size () == 1 ) {
121
121
addSetMethod (propName , firstMethod );
122
122
} else {
123
- Class expectedType = getTypes .get (propName );
123
+ Class <?> expectedType = getTypes .get (propName );
124
124
if (expectedType == null ) {
125
125
throw new ReflectionException ("Illegal overloaded setter method with ambiguous type for property "
126
126
+ propName + " in class " + firstMethod .getDeclaringClass () + ". This breaks the JavaBeans " +
@@ -154,7 +154,7 @@ private void addSetMethod(String name, Method method) {
154
154
}
155
155
}
156
156
157
- private void addFields (Class clazz ) {
157
+ private void addFields (Class <?> clazz ) {
158
158
Field [] fields = clazz .getDeclaredFields ();
159
159
for (Field field : fields ) {
160
160
if (canAccessPrivateMethods ()) {
@@ -166,9 +166,9 @@ private void addFields(Class clazz) {
166
166
}
167
167
if (field .isAccessible ()) {
168
168
if (!setMethods .containsKey (field .getName ())) {
169
- if (! Modifier . isFinal ( field . getModifiers ())) {
170
- addSetField ( field );
171
- }
169
+ // issue 379 - removed the check for final because JDK 1.5 allows
170
+ // modification of final fields through reflection (JSR-133). (JGB)
171
+ addSetField ( field );
172
172
}
173
173
if (!getMethods .containsKey (field .getName ())) {
174
174
addGetField (field );
@@ -207,16 +207,16 @@ private boolean isValidPropertyName(String name) {
207
207
* @param cls The class
208
208
* @return An array containing all methods in this class
209
209
*/
210
- private Method [] getClassMethods (Class cls ) {
210
+ private Method [] getClassMethods (Class <?> cls ) {
211
211
HashMap <String , Method > uniqueMethods = new HashMap <String , Method >();
212
- Class currentClass = cls ;
212
+ Class <?> currentClass = cls ;
213
213
while (currentClass != null ) {
214
214
addUniqueMethods (uniqueMethods , currentClass .getDeclaredMethods ());
215
215
216
216
// we also need to look for interface methods -
217
217
// because the class may be abstract
218
- Class [] interfaces = currentClass .getInterfaces ();
219
- for (Class anInterface : interfaces ) {
218
+ Class <?> [] interfaces = currentClass .getInterfaces ();
219
+ for (Class <?> anInterface : interfaces ) {
220
220
addUniqueMethods (uniqueMethods , anInterface .getMethods ());
221
221
}
222
222
@@ -253,7 +253,7 @@ private void addUniqueMethods(HashMap<String, Method> uniqueMethods, Method[] me
253
253
private String getSignature (Method method ) {
254
254
StringBuffer sb = new StringBuffer ();
255
255
sb .append (method .getName ());
256
- Class [] parameters = method .getParameterTypes ();
256
+ Class <?> [] parameters = method .getParameterTypes ();
257
257
for (int i = 0 ; i < parameters .length ; i ++) {
258
258
if (i == 0 ) {
259
259
sb .append (':' );
@@ -282,11 +282,11 @@ private static boolean canAccessPrivateMethods() {
282
282
*
283
283
* @return The class name
284
284
*/
285
- public Class getType () {
285
+ public Class <?> getType () {
286
286
return type ;
287
287
}
288
288
289
- public Constructor getDefaultConstructor () {
289
+ public Constructor <?> getDefaultConstructor () {
290
290
if (defaultConstructor != null ) {
291
291
return defaultConstructor ;
292
292
} else {
@@ -316,8 +316,8 @@ public Invoker getGetInvoker(String propertyName) {
316
316
* @param propertyName - the name of the property
317
317
* @return The Class of the propery setter
318
318
*/
319
- public Class getSetterType (String propertyName ) {
320
- Class clazz = setTypes .get (propertyName );
319
+ public Class <?> getSetterType (String propertyName ) {
320
+ Class <?> clazz = setTypes .get (propertyName );
321
321
if (clazz == null ) {
322
322
throw new ReflectionException ("There is no setter for property named '" + propertyName + "' in '" + type + "'" );
323
323
}
@@ -330,8 +330,8 @@ public Class getSetterType(String propertyName) {
330
330
* @param propertyName - the name of the property
331
331
* @return The Class of the propery getter
332
332
*/
333
- public Class getGetterType (String propertyName ) {
334
- Class clazz = getTypes .get (propertyName );
333
+ public Class <?> getGetterType (String propertyName ) {
334
+ Class <?> clazz = getTypes .get (propertyName );
335
335
if (clazz == null ) {
336
336
throw new ReflectionException ("There is no getter for property named '" + propertyName + "' in '" + type + "'" );
337
337
}
@@ -386,7 +386,7 @@ public String findPropertyName(String name) {
386
386
* @param clazz The class for which to lookup the method cache.
387
387
* @return The method cache for the class
388
388
*/
389
- public static Reflector forClass (Class clazz ) {
389
+ public static Reflector forClass (Class <?> clazz ) {
390
390
if (classCacheEnabled ) {
391
391
synchronized (clazz ) {
392
392
Reflector cached = REFLECTOR_MAP .get (clazz );
@@ -408,8 +408,4 @@ public static void setClassCacheEnabled(boolean classCacheEnabled) {
408
408
public static boolean isClassCacheEnabled () {
409
409
return classCacheEnabled ;
410
410
}
411
-
412
411
}
413
-
414
-
415
-
0 commit comments