11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2828import org .springframework .core .GenericTypeResolver ;
2929import org .springframework .core .MethodParameter ;
3030import org .springframework .util .ClassUtils ;
31+ import org .springframework .util .ObjectUtils ;
3132import org .springframework .util .StringUtils ;
3233
3334/**
3839 * @author Juergen Hoeller
3940 * @since 2.5.2
4041 */
41- class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
42+ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
4243
4344 private final Class <?> beanClass ;
4445
4546 private final Method readMethod ;
4647
4748 private final Method writeMethod ;
4849
49- private final Class <?> propertyEditorClass ;
50-
5150 private volatile Set <Method > ambiguousWriteMethods ;
5251
52+ private MethodParameter writeMethodParameter ;
53+
5354 private Class <?> propertyType ;
5455
55- private MethodParameter writeMethodParameter ;
56+ private final Class <?> propertyEditorClass ;
5657
5758
5859 public GenericTypeAwarePropertyDescriptor (Class <?> beanClass , String propertyName ,
5960 Method readMethod , Method writeMethod , Class <?> propertyEditorClass )
6061 throws IntrospectionException {
6162
6263 super (propertyName , null , null );
64+
65+ if (beanClass == null ) {
66+ throw new IntrospectionException ("Bean class must not be null" );
67+ }
6368 this .beanClass = beanClass ;
64- this .propertyEditorClass = propertyEditorClass ;
6569
6670 Method readMethodToUse = BridgeMethodResolver .findBridgedMethod (readMethod );
6771 Method writeMethodToUse = BridgeMethodResolver .findBridgedMethod (writeMethod );
@@ -93,8 +97,11 @@ public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyNam
9397 this .ambiguousWriteMethods = ambiguousCandidates ;
9498 }
9599 }
100+
101+ this .propertyEditorClass = propertyEditorClass ;
96102 }
97103
104+
98105 public Class <?> getBeanClass () {
99106 return this .beanClass ;
100107 }
@@ -120,9 +127,15 @@ public Method getWriteMethodForActualAccess() {
120127 return this .writeMethod ;
121128 }
122129
123- @ Override
124- public Class <?> getPropertyEditorClass () {
125- return this .propertyEditorClass ;
130+ public synchronized MethodParameter getWriteMethodParameter () {
131+ if (this .writeMethod == null ) {
132+ return null ;
133+ }
134+ if (this .writeMethodParameter == null ) {
135+ this .writeMethodParameter = new MethodParameter (this .writeMethod , 0 );
136+ GenericTypeResolver .resolveParameterType (this .writeMethodParameter , this .beanClass );
137+ }
138+ return this .writeMethodParameter ;
126139 }
127140
128141 @ Override
@@ -144,15 +157,34 @@ public synchronized Class<?> getPropertyType() {
144157 return this .propertyType ;
145158 }
146159
147- public synchronized MethodParameter getWriteMethodParameter () {
148- if (this .writeMethod == null ) {
149- return null ;
160+ @ Override
161+ public Class <?> getPropertyEditorClass () {
162+ return this .propertyEditorClass ;
163+ }
164+
165+
166+ @ Override
167+ public boolean equals (Object other ) {
168+ if (this == other ) {
169+ return true ;
150170 }
151- if (this .writeMethodParameter == null ) {
152- this .writeMethodParameter = new MethodParameter (this .writeMethod , 0 );
153- GenericTypeResolver .resolveParameterType (this .writeMethodParameter , this .beanClass );
171+ if (!(other instanceof GenericTypeAwarePropertyDescriptor )) {
172+ return false ;
154173 }
155- return this .writeMethodParameter ;
174+ GenericTypeAwarePropertyDescriptor otherPd = (GenericTypeAwarePropertyDescriptor ) other ;
175+ return (getBeanClass ().equals (otherPd .getBeanClass ()) &&
176+ ObjectUtils .nullSafeEquals (getReadMethod (), otherPd .getReadMethod ()) &&
177+ ObjectUtils .nullSafeEquals (getWriteMethod (), otherPd .getWriteMethod ()) &&
178+ ObjectUtils .nullSafeEquals (getPropertyEditorClass (), otherPd .getPropertyEditorClass ()) &&
179+ isBound () == otherPd .isBound () && isConstrained () == otherPd .isConstrained ());
180+ }
181+
182+ @ Override
183+ public int hashCode () {
184+ int hashCode = getBeanClass ().hashCode ();
185+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (getReadMethod ());
186+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (getWriteMethod ());
187+ return hashCode ;
156188 }
157189
158190}
0 commit comments