16
16
17
17
package org .springframework .core ;
18
18
19
- import java .lang .ref .Reference ;
20
- import java .lang .ref .WeakReference ;
21
19
import java .lang .reflect .Array ;
22
20
import java .lang .reflect .GenericArrayType ;
23
21
import java .lang .reflect .Method ;
24
22
import java .lang .reflect .ParameterizedType ;
25
23
import java .lang .reflect .Type ;
26
24
import java .lang .reflect .TypeVariable ;
27
25
import java .lang .reflect .WildcardType ;
28
- import java .util .Collections ;
29
26
import java .util .HashMap ;
30
27
import java .util .Map ;
31
- import java .util .WeakHashMap ;
32
28
33
29
import org .apache .commons .logging .Log ;
34
30
import org .apache .commons .logging .LogFactory ;
35
31
36
32
import org .springframework .util .Assert ;
37
33
import org .springframework .util .ObjectUtils ;
34
+ import org .springframework .util .ConcurrentReferenceHashMap ;
38
35
39
36
/**
40
37
* Helper class for resolving generic types against type variables.
@@ -53,9 +50,8 @@ public abstract class GenericTypeResolver {
53
50
private static final Log logger = LogFactory .getLog (GenericTypeResolver .class );
54
51
55
52
/** Cache from Class to TypeVariable Map */
56
- private static final Map <Class , Reference <Map <TypeVariable , Type >>> typeVariableCache =
57
- Collections .synchronizedMap (new WeakHashMap <Class , Reference <Map <TypeVariable , Type >>>());
58
-
53
+ private static final Map <Class , Map <TypeVariable , Type >> typeVariableCache =
54
+ new ConcurrentReferenceHashMap <Class , Map <TypeVariable ,Type >>();
59
55
60
56
/**
61
57
* Determine the target type for the given parameter specification.
@@ -408,8 +404,8 @@ static Type getRawType(Type genericType, Map<TypeVariable, Type> typeVariableMap
408
404
* all super types, enclosing types and interfaces.
409
405
*/
410
406
public static Map <TypeVariable , Type > getTypeVariableMap (Class clazz ) {
411
- Reference < Map <TypeVariable , Type > > ref = typeVariableCache .get (clazz );
412
- Map <TypeVariable , Type > typeVariableMap = (ref != null ? ref . get () : null );
407
+ Map <TypeVariable , Type > ref = typeVariableCache .get (clazz );
408
+ Map <TypeVariable , Type > typeVariableMap = (ref != null ? ref : null );
413
409
414
410
if (typeVariableMap == null ) {
415
411
typeVariableMap = new HashMap <TypeVariable , Type >();
@@ -441,7 +437,7 @@ public static Map<TypeVariable, Type> getTypeVariableMap(Class clazz) {
441
437
type = type .getEnclosingClass ();
442
438
}
443
439
444
- typeVariableCache .put (clazz , new WeakReference < Map < TypeVariable , Type >>( typeVariableMap ) );
440
+ typeVariableCache .put (clazz , typeVariableMap );
445
441
}
446
442
447
443
return typeVariableMap ;
0 commit comments