@@ -173,11 +173,14 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
173173 @ Nullable
174174 private String factoryMethodName ;
175175
176+ @ Nullable
176177 private ConstructorArgumentValues constructorArgumentValues ;
177178
179+ @ Nullable
178180 private MutablePropertyValues propertyValues ;
179181
180- private MethodOverrides methodOverrides = new MethodOverrides ();
182+ @ Nullable
183+ private MethodOverrides methodOverrides ;
181184
182185 @ Nullable
183186 private String initMethodName ;
@@ -212,8 +215,8 @@ protected AbstractBeanDefinition() {
212215 * constructor argument values and property values.
213216 */
214217 protected AbstractBeanDefinition (@ Nullable ConstructorArgumentValues cargs , @ Nullable MutablePropertyValues pvs ) {
215- this .constructorArgumentValues = ( cargs != null ? cargs : new ConstructorArgumentValues ()) ;
216- this .propertyValues = ( pvs != null ? pvs : new MutablePropertyValues ()) ;
218+ this .constructorArgumentValues = cargs ;
219+ this .propertyValues = pvs ;
217220 }
218221
219222 /**
@@ -229,8 +232,6 @@ protected AbstractBeanDefinition(BeanDefinition original) {
229232 setLazyInit (original .isLazyInit ());
230233 setFactoryBeanName (original .getFactoryBeanName ());
231234 setFactoryMethodName (original .getFactoryMethodName ());
232- this .constructorArgumentValues = new ConstructorArgumentValues (original .getConstructorArgumentValues ());
233- this .propertyValues = new MutablePropertyValues (original .getPropertyValues ());
234235 setRole (original .getRole ());
235236 setSource (original .getSource ());
236237 copyAttributesFrom (original );
@@ -240,6 +241,15 @@ protected AbstractBeanDefinition(BeanDefinition original) {
240241 if (originalAbd .hasBeanClass ()) {
241242 setBeanClass (originalAbd .getBeanClass ());
242243 }
244+ if (originalAbd .hasConstructorArgumentValues ()) {
245+ setConstructorArgumentValues (new ConstructorArgumentValues (original .getConstructorArgumentValues ()));
246+ }
247+ if (originalAbd .hasPropertyValues ()) {
248+ setPropertyValues (new MutablePropertyValues (original .getPropertyValues ()));
249+ }
250+ if (originalAbd .hasMethodOverrides ()) {
251+ setMethodOverrides (new MethodOverrides (originalAbd .getMethodOverrides ()));
252+ }
243253 setAutowireMode (originalAbd .getAutowireMode ());
244254 setDependencyCheck (originalAbd .getDependencyCheck ());
245255 setDependsOn (originalAbd .getDependsOn ());
@@ -249,7 +259,6 @@ protected AbstractBeanDefinition(BeanDefinition original) {
249259 setInstanceSupplier (originalAbd .getInstanceSupplier ());
250260 setNonPublicAccessAllowed (originalAbd .isNonPublicAccessAllowed ());
251261 setLenientConstructorResolution (originalAbd .isLenientConstructorResolution ());
252- setMethodOverrides (new MethodOverrides (originalAbd .getMethodOverrides ()));
253262 setInitMethodName (originalAbd .getInitMethodName ());
254263 setEnforceInitMethod (originalAbd .isEnforceInitMethod ());
255264 setDestroyMethodName (originalAbd .getDestroyMethodName ());
@@ -258,6 +267,8 @@ protected AbstractBeanDefinition(BeanDefinition original) {
258267 setResource (originalAbd .getResource ());
259268 }
260269 else {
270+ setConstructorArgumentValues (new ConstructorArgumentValues (original .getConstructorArgumentValues ()));
271+ setPropertyValues (new MutablePropertyValues (original .getPropertyValues ()));
261272 setResourceDescription (original .getResourceDescription ());
262273 }
263274 }
@@ -294,8 +305,6 @@ public void overrideFrom(BeanDefinition other) {
294305 if (StringUtils .hasLength (other .getFactoryMethodName ())) {
295306 setFactoryMethodName (other .getFactoryMethodName ());
296307 }
297- getConstructorArgumentValues ().addArgumentValues (other .getConstructorArgumentValues ());
298- getPropertyValues ().addPropertyValues (other .getPropertyValues ());
299308 setRole (other .getRole ());
300309 setSource (other .getSource ());
301310 copyAttributesFrom (other );
@@ -305,6 +314,15 @@ public void overrideFrom(BeanDefinition other) {
305314 if (otherAbd .hasBeanClass ()) {
306315 setBeanClass (otherAbd .getBeanClass ());
307316 }
317+ if (otherAbd .hasConstructorArgumentValues ()) {
318+ getConstructorArgumentValues ().addArgumentValues (other .getConstructorArgumentValues ());
319+ }
320+ if (otherAbd .hasPropertyValues ()) {
321+ getPropertyValues ().addPropertyValues (other .getPropertyValues ());
322+ }
323+ if (otherAbd .hasMethodOverrides ()) {
324+ getMethodOverrides ().addOverrides (otherAbd .getMethodOverrides ());
325+ }
308326 setAutowireMode (otherAbd .getAutowireMode ());
309327 setDependencyCheck (otherAbd .getDependencyCheck ());
310328 setDependsOn (otherAbd .getDependsOn ());
@@ -314,7 +332,6 @@ public void overrideFrom(BeanDefinition other) {
314332 setInstanceSupplier (otherAbd .getInstanceSupplier ());
315333 setNonPublicAccessAllowed (otherAbd .isNonPublicAccessAllowed ());
316334 setLenientConstructorResolution (otherAbd .isLenientConstructorResolution ());
317- getMethodOverrides ().addOverrides (otherAbd .getMethodOverrides ());
318335 if (otherAbd .getInitMethodName () != null ) {
319336 setInitMethodName (otherAbd .getInitMethodName ());
320337 setEnforceInitMethod (otherAbd .isEnforceInitMethod ());
@@ -327,6 +344,8 @@ public void overrideFrom(BeanDefinition other) {
327344 setResource (otherAbd .getResource ());
328345 }
329346 else {
347+ getConstructorArgumentValues ().addArgumentValues (other .getConstructorArgumentValues ());
348+ getPropertyValues ().addPropertyValues (other .getPropertyValues ());
330349 setResourceDescription (other .getResourceDescription ());
331350 }
332351 }
@@ -778,46 +797,59 @@ public String getFactoryMethodName() {
778797 /**
779798 * Specify constructor argument values for this bean.
780799 */
781- public void setConstructorArgumentValues (@ Nullable ConstructorArgumentValues constructorArgumentValues ) {
782- this .constructorArgumentValues =
783- (constructorArgumentValues != null ? constructorArgumentValues : new ConstructorArgumentValues ());
800+ public void setConstructorArgumentValues (ConstructorArgumentValues constructorArgumentValues ) {
801+ this .constructorArgumentValues = constructorArgumentValues ;
784802 }
785803
786804 /**
787805 * Return constructor argument values for this bean (never {@code null}).
788806 */
789807 @ Override
790808 public ConstructorArgumentValues getConstructorArgumentValues () {
809+ if (this .constructorArgumentValues == null ) {
810+ this .constructorArgumentValues = new ConstructorArgumentValues ();
811+ }
791812 return this .constructorArgumentValues ;
792813 }
793814
794815 /**
795816 * Return if there are constructor argument values defined for this bean.
796817 */
797818 public boolean hasConstructorArgumentValues () {
798- return ! this .constructorArgumentValues .isEmpty ();
819+ return ( this . constructorArgumentValues != null && ! this .constructorArgumentValues .isEmpty () );
799820 }
800821
801822 /**
802823 * Specify property values for this bean, if any.
803824 */
804- public void setPropertyValues (@ Nullable MutablePropertyValues propertyValues ) {
805- this .propertyValues = ( propertyValues != null ? propertyValues : new MutablePropertyValues ()) ;
825+ public void setPropertyValues (MutablePropertyValues propertyValues ) {
826+ this .propertyValues = propertyValues ;
806827 }
807828
808829 /**
809830 * Return property values for this bean (never {@code null}).
810831 */
811832 @ Override
812833 public MutablePropertyValues getPropertyValues () {
834+ if (this .propertyValues == null ) {
835+ this .propertyValues = new MutablePropertyValues ();
836+ }
813837 return this .propertyValues ;
814838 }
815839
840+ /**
841+ * Return if there are property values values defined for this bean.
842+ * @since 5.0.2
843+ */
844+ public boolean hasPropertyValues () {
845+ return (this .propertyValues != null && !this .propertyValues .isEmpty ());
846+ }
847+
816848 /**
817849 * Specify method overrides for the bean, if any.
818850 */
819- public void setMethodOverrides (@ Nullable MethodOverrides methodOverrides ) {
820- this .methodOverrides = ( methodOverrides != null ? methodOverrides : new MethodOverrides ()) ;
851+ public void setMethodOverrides (MethodOverrides methodOverrides ) {
852+ this .methodOverrides = methodOverrides ;
821853 }
822854
823855 /**
@@ -826,9 +858,20 @@ public void setMethodOverrides(@Nullable MethodOverrides methodOverrides) {
826858 * <p>Never returns {@code null}.
827859 */
828860 public MethodOverrides getMethodOverrides () {
861+ if (this .methodOverrides == null ) {
862+ this .methodOverrides = new MethodOverrides ();
863+ }
829864 return this .methodOverrides ;
830865 }
831866
867+ /**
868+ * Return if there are method overrides defined for this bean.
869+ * @since 5.0.2
870+ */
871+ public boolean hasMethodOverrides () {
872+ return (this .methodOverrides != null && !this .methodOverrides .isEmpty ());
873+ }
874+
832875 /**
833876 * Set the name of the initializer method.
834877 * <p>The default is {@code null} in which case there is no initializer method.
@@ -1002,7 +1045,7 @@ public BeanDefinition getOriginatingBeanDefinition() {
10021045 * @throws BeanDefinitionValidationException in case of validation failure
10031046 */
10041047 public void validate () throws BeanDefinitionValidationException {
1005- if (! getMethodOverrides (). isEmpty () && getFactoryMethodName () != null ) {
1048+ if (hasMethodOverrides () && getFactoryMethodName () != null ) {
10061049 throw new BeanDefinitionValidationException (
10071050 "Cannot combine static factory method with method overrides: " +
10081051 "the static factory method must create the instance" );
@@ -1020,9 +1063,8 @@ public void validate() throws BeanDefinitionValidationException {
10201063 */
10211064 public void prepareMethodOverrides () throws BeanDefinitionValidationException {
10221065 // Check that lookup methods exists.
1023- MethodOverrides methodOverrides = getMethodOverrides ();
1024- if (!methodOverrides .isEmpty ()) {
1025- Set <MethodOverride > overrides = methodOverrides .getOverrides ();
1066+ if (hasMethodOverrides ()) {
1067+ Set <MethodOverride > overrides = getMethodOverrides ().getOverrides ();
10261068 synchronized (overrides ) {
10271069 for (MethodOverride mo : overrides ) {
10281070 prepareMethodOverride (mo );
0 commit comments