Skip to content

Commit 5fe608d

Browse files
committed
PropertyValue stores source object in common superclass field
Issue: SPR-8337 (cherry picked from commit 53dc996)
1 parent 71fd621 commit 5fe608d

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

spring-beans/src/main/java/org/springframework/beans/PropertyValue.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -46,8 +46,6 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
4646

4747
private final Object value;
4848

49-
private Object source;
50-
5149
private boolean optional = false;
5250

5351
private boolean converted = false;
@@ -82,13 +80,13 @@ public PropertyValue(PropertyValue original) {
8280
Assert.notNull(original, "Original must not be null");
8381
this.name = original.getName();
8482
this.value = original.getValue();
85-
this.source = original.getSource();
8683
this.optional = original.isOptional();
8784
this.converted = original.converted;
8885
this.convertedValue = original.convertedValue;
8986
this.conversionNecessary = original.conversionNecessary;
9087
this.resolvedTokens = original.resolvedTokens;
9188
this.resolvedDescriptor = original.resolvedDescriptor;
89+
setSource(original.getSource());
9290
copyAttributesFrom(original);
9391
}
9492

@@ -102,11 +100,11 @@ public PropertyValue(PropertyValue original, Object newValue) {
102100
Assert.notNull(original, "Original must not be null");
103101
this.name = original.getName();
104102
this.value = newValue;
105-
this.source = original;
106103
this.optional = original.isOptional();
107104
this.conversionNecessary = original.conversionNecessary;
108105
this.resolvedTokens = original.resolvedTokens;
109106
this.resolvedDescriptor = original.resolvedDescriptor;
107+
setSource(original);
110108
copyAttributesFrom(original);
111109
}
112110

@@ -135,16 +133,28 @@ public Object getValue() {
135133
*/
136134
public PropertyValue getOriginalPropertyValue() {
137135
PropertyValue original = this;
138-
while (original.source instanceof PropertyValue && original.source != original) {
139-
original = (PropertyValue) original.source;
136+
Object source = getSource();
137+
while (source instanceof PropertyValue && source != original) {
138+
original = (PropertyValue) source;
139+
source = original.getSource();
140140
}
141141
return original;
142142
}
143143

144+
/**
145+
* Set whether this is an optional value, that is, to be ignored
146+
* when no corresponding property exists on the target class.
147+
* @since 3.0
148+
*/
144149
public void setOptional(boolean optional) {
145150
this.optional = optional;
146151
}
147152

153+
/**
154+
* Return whether this is an optional value, that is, to be ignored
155+
* when no corresponding property exists on the target class.
156+
* @since 3.0
157+
*/
148158
public boolean isOptional() {
149159
return this.optional;
150160
}
@@ -186,7 +196,7 @@ public boolean equals(Object other) {
186196
PropertyValue otherPv = (PropertyValue) other;
187197
return (this.name.equals(otherPv.name) &&
188198
ObjectUtils.nullSafeEquals(this.value, otherPv.value) &&
189-
ObjectUtils.nullSafeEquals(this.source, otherPv.source));
199+
ObjectUtils.nullSafeEquals(getSource(), otherPv.getSource()));
190200
}
191201

192202
@Override

0 commit comments

Comments
 (0)