2929import org .springframework .core .MethodParameter ;
3030import org .springframework .core .convert .Property ;
3131import org .springframework .core .convert .TypeDescriptor ;
32+ import org .springframework .core .style .ToStringCreator ;
3233import org .springframework .expression .AccessException ;
3334import org .springframework .expression .EvaluationContext ;
3435import org .springframework .expression .EvaluationException ;
@@ -71,7 +72,7 @@ public boolean canRead(EvaluationContext context, Object target, String name) th
7172 if (type .isArray () && name .equals ("length" )) {
7273 return true ;
7374 }
74- CacheKey cacheKey = new CacheKey (type , name );
75+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
7576 if (this .readerCache .containsKey (cacheKey )) {
7677 return true ;
7778 }
@@ -110,7 +111,7 @@ public TypedValue read(EvaluationContext context, Object target, String name) th
110111 return new TypedValue (Array .getLength (target ));
111112 }
112113
113- CacheKey cacheKey = new CacheKey (type , name );
114+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
114115 InvokerPair invoker = this .readerCache .get (cacheKey );
115116
116117 if (invoker == null || invoker .member instanceof Method ) {
@@ -168,7 +169,7 @@ public boolean canWrite(EvaluationContext context, Object target, String name) t
168169 return false ;
169170 }
170171 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 );
172173 if (this .writerCache .containsKey (cacheKey )) {
173174 return true ;
174175 }
@@ -209,7 +210,7 @@ public void write(EvaluationContext context, Object target, String name, Object
209210 throw new AccessException ("Type conversion failure" ,evaluationException );
210211 }
211212 }
212- CacheKey cacheKey = new CacheKey (type , name );
213+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
213214 Member cachedMember = this .writerCache .get (cacheKey );
214215
215216 if (cachedMember == null || cachedMember instanceof Method ) {
@@ -266,7 +267,7 @@ private TypeDescriptor getTypeDescriptor(EvaluationContext context, Object targe
266267 if (type .isArray () && name .equals ("length" )) {
267268 return TypeDescriptor .valueOf (Integer .TYPE );
268269 }
269- CacheKey cacheKey = new CacheKey (type , name );
270+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
270271 TypeDescriptor typeDescriptor = this .typeDescriptorCache .get (cacheKey );
271272 if (typeDescriptor == null ) {
272273 // attempt to populate the cache entry
@@ -417,7 +418,7 @@ public PropertyAccessor createOptimalAccessor(EvaluationContext eContext, Object
417418 return this ;
418419 }
419420
420- CacheKey cacheKey = new CacheKey (type , name );
421+ CacheKey cacheKey = new CacheKey (type , name , target instanceof Class );
421422 InvokerPair invocationTarget = this .readerCache .get (cacheKey );
422423
423424 if (invocationTarget == null || invocationTarget .member instanceof Method ) {
@@ -476,9 +477,12 @@ private static class CacheKey {
476477
477478 private final String name ;
478479
479- public CacheKey (Class clazz , String name ) {
480+ private boolean targetIsClass ;
481+
482+ public CacheKey (Class clazz , String name , boolean targetIsClass ) {
480483 this .clazz = clazz ;
481484 this .name = name ;
485+ this .targetIsClass = targetIsClass ;
482486 }
483487
484488 @ Override
@@ -490,13 +494,23 @@ public boolean equals(Object other) {
490494 return false ;
491495 }
492496 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 ;
494502 }
495503
496504 @ Override
497505 public int hashCode () {
498506 return this .clazz .hashCode () * 29 + this .name .hashCode ();
499507 }
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+ }
500514 }
501515
502516
0 commit comments