29
29
import org .springframework .core .MethodParameter ;
30
30
import org .springframework .core .convert .Property ;
31
31
import org .springframework .core .convert .TypeDescriptor ;
32
+ import org .springframework .core .style .ToStringCreator ;
32
33
import org .springframework .expression .AccessException ;
33
34
import org .springframework .expression .EvaluationContext ;
34
35
import org .springframework .expression .EvaluationException ;
@@ -71,7 +72,7 @@ public boolean canRead(EvaluationContext context, Object target, String name) th
71
72
if (type .isArray () && name .equals ("length" )) {
72
73
return true ;
73
74
}
74
- CacheKey cacheKey = new CacheKey (type , name );
75
+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
75
76
if (this .readerCache .containsKey (cacheKey )) {
76
77
return true ;
77
78
}
@@ -110,7 +111,7 @@ public TypedValue read(EvaluationContext context, Object target, String name) th
110
111
return new TypedValue (Array .getLength (target ));
111
112
}
112
113
113
- CacheKey cacheKey = new CacheKey (type , name );
114
+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
114
115
InvokerPair invoker = this .readerCache .get (cacheKey );
115
116
116
117
if (invoker == null || invoker .member instanceof Method ) {
@@ -168,7 +169,7 @@ public boolean canWrite(EvaluationContext context, Object target, String name) t
168
169
return false ;
169
170
}
170
171
Class <?> type = (target instanceof Class ? (Class <?>) target : target .getClass ());
171
- CacheKey cacheKey = new CacheKey (type , name );
172
+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
172
173
if (this .writerCache .containsKey (cacheKey )) {
173
174
return true ;
174
175
}
@@ -209,7 +210,7 @@ public void write(EvaluationContext context, Object target, String name, Object
209
210
throw new AccessException ("Type conversion failure" ,evaluationException );
210
211
}
211
212
}
212
- CacheKey cacheKey = new CacheKey (type , name );
213
+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
213
214
Member cachedMember = this .writerCache .get (cacheKey );
214
215
215
216
if (cachedMember == null || cachedMember instanceof Method ) {
@@ -266,7 +267,7 @@ private TypeDescriptor getTypeDescriptor(EvaluationContext context, Object targe
266
267
if (type .isArray () && name .equals ("length" )) {
267
268
return TypeDescriptor .valueOf (Integer .TYPE );
268
269
}
269
- CacheKey cacheKey = new CacheKey (type , name );
270
+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
270
271
TypeDescriptor typeDescriptor = this .typeDescriptorCache .get (cacheKey );
271
272
if (typeDescriptor == null ) {
272
273
// attempt to populate the cache entry
@@ -417,7 +418,7 @@ public PropertyAccessor createOptimalAccessor(EvaluationContext eContext, Object
417
418
return this ;
418
419
}
419
420
420
- CacheKey cacheKey = new CacheKey (type , name );
421
+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
421
422
InvokerPair invocationTarget = this .readerCache .get (cacheKey );
422
423
423
424
if (invocationTarget == null || invocationTarget .member instanceof Method ) {
@@ -476,9 +477,12 @@ private static class CacheKey {
476
477
477
478
private final String name ;
478
479
479
- public CacheKey (Class clazz , String name ) {
480
+ private boolean targetIsClass ;
481
+
482
+ public CacheKey (Class clazz , String name , boolean targetIsClass ) {
480
483
this .clazz = clazz ;
481
484
this .name = name ;
485
+ this .targetIsClass = targetIsClass ;
482
486
}
483
487
484
488
@ Override
@@ -490,13 +494,23 @@ public boolean equals(Object other) {
490
494
return false ;
491
495
}
492
496
CacheKey otherKey = (CacheKey ) other ;
493
- return (this .clazz .equals (otherKey .clazz ) && this .name .equals (otherKey .name ));
497
+ boolean rtn = true ;
498
+ rtn &= this .clazz .equals (otherKey .clazz );
499
+ rtn &= this .name .equals (otherKey .name );
500
+ rtn &= this .targetIsClass == otherKey .targetIsClass ;
501
+ return rtn ;
494
502
}
495
503
496
504
@ Override
497
505
public int hashCode () {
498
506
return this .clazz .hashCode () * 29 + this .name .hashCode ();
499
507
}
508
+
509
+ @ Override
510
+ public String toString () {
511
+ return new ToStringCreator (this ).append ("clazz" , this .clazz ).append ("name" ,
512
+ this .name ).append ("targetIsClass" , this .targetIsClass ).toString ();
513
+ }
500
514
}
501
515
502
516
0 commit comments