Skip to content

Commit 367949e

Browse files
committed
PropertyValue stores source object in common superclass field
Issue: SPR-8337 (cherry picked from commit fa820bc)
1 parent ae2bbe7 commit 367949e

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
4545

4646
private final Object value;
4747

48-
private Object source;
49-
5048
private boolean optional = false;
5149

5250
private boolean converted = false;
@@ -78,12 +76,12 @@ public PropertyValue(PropertyValue original) {
7876
Assert.notNull(original, "Original must not be null");
7977
this.name = original.getName();
8078
this.value = original.getValue();
81-
this.source = original.getSource();
8279
this.optional = original.isOptional();
8380
this.converted = original.converted;
8481
this.convertedValue = original.convertedValue;
8582
this.conversionNecessary = original.conversionNecessary;
8683
this.resolvedTokens = original.resolvedTokens;
84+
setSource(original.getSource());
8785
copyAttributesFrom(original);
8886
}
8987

@@ -97,10 +95,10 @@ public PropertyValue(PropertyValue original, Object newValue) {
9795
Assert.notNull(original, "Original must not be null");
9896
this.name = original.getName();
9997
this.value = newValue;
100-
this.source = original;
10198
this.optional = original.isOptional();
10299
this.conversionNecessary = original.conversionNecessary;
103100
this.resolvedTokens = original.resolvedTokens;
101+
setSource(original);
104102
copyAttributesFrom(original);
105103
}
106104

@@ -129,16 +127,28 @@ public Object getValue() {
129127
*/
130128
public PropertyValue getOriginalPropertyValue() {
131129
PropertyValue original = this;
132-
while (original.source instanceof PropertyValue && original.source != original) {
133-
original = (PropertyValue) original.source;
130+
Object source = getSource();
131+
while (source instanceof PropertyValue && source != original) {
132+
original = (PropertyValue) source;
133+
source = original.getSource();
134134
}
135135
return original;
136136
}
137137

138+
/**
139+
* Set whether this is an optional value, that is, to be ignored
140+
* when no corresponding property exists on the target class.
141+
* @since 3.0
142+
*/
138143
public void setOptional(boolean optional) {
139144
this.optional = optional;
140145
}
141146

147+
/**
148+
* Reeurn whether this is an optional value, that is, to be ignored
149+
* when no corresponding property exists on the target class.
150+
* @since 3.0
151+
*/
142152
public boolean isOptional() {
143153
return this.optional;
144154
}
@@ -180,7 +190,7 @@ public boolean equals(Object other) {
180190
PropertyValue otherPv = (PropertyValue) other;
181191
return (this.name.equals(otherPv.name) &&
182192
ObjectUtils.nullSafeEquals(this.value, otherPv.value) &&
183-
ObjectUtils.nullSafeEquals(this.source, otherPv.source));
193+
ObjectUtils.nullSafeEquals(getSource(), otherPv.getSource()));
184194
}
185195

186196
@Override

0 commit comments

Comments
 (0)