Skip to content

Commit

Permalink
PropertyValue stores source object in common superclass field
Browse files Browse the repository at this point in the history
Issue: SPR-8337
(cherry picked from commit 53dc996)
  • Loading branch information
jhoeller committed Sep 13, 2016
1 parent 71fd621 commit 5fe608d
Showing 1 changed file with 18 additions and 8 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,8 +46,6 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri

private final Object value;

private Object source;

private boolean optional = false;

private boolean converted = false;
Expand Down Expand Up @@ -82,13 +80,13 @@ public PropertyValue(PropertyValue original) {
Assert.notNull(original, "Original must not be null");
this.name = original.getName();
this.value = original.getValue();
this.source = original.getSource();
this.optional = original.isOptional();
this.converted = original.converted;
this.convertedValue = original.convertedValue;
this.conversionNecessary = original.conversionNecessary;
this.resolvedTokens = original.resolvedTokens;
this.resolvedDescriptor = original.resolvedDescriptor;
setSource(original.getSource());
copyAttributesFrom(original);
}

Expand All @@ -102,11 +100,11 @@ public PropertyValue(PropertyValue original, Object newValue) {
Assert.notNull(original, "Original must not be null");
this.name = original.getName();
this.value = newValue;
this.source = original;
this.optional = original.isOptional();
this.conversionNecessary = original.conversionNecessary;
this.resolvedTokens = original.resolvedTokens;
this.resolvedDescriptor = original.resolvedDescriptor;
setSource(original);
copyAttributesFrom(original);
}

Expand Down Expand Up @@ -135,16 +133,28 @@ public Object getValue() {
*/
public PropertyValue getOriginalPropertyValue() {
PropertyValue original = this;
while (original.source instanceof PropertyValue && original.source != original) {
original = (PropertyValue) original.source;
Object source = getSource();
while (source instanceof PropertyValue && source != original) {
original = (PropertyValue) source;
source = original.getSource();
}
return original;
}

/**
* Set whether this is an optional value, that is, to be ignored
* when no corresponding property exists on the target class.
* @since 3.0
*/
public void setOptional(boolean optional) {
this.optional = optional;
}

/**
* Return whether this is an optional value, that is, to be ignored
* when no corresponding property exists on the target class.
* @since 3.0
*/
public boolean isOptional() {
return this.optional;
}
Expand Down Expand Up @@ -186,7 +196,7 @@ public boolean equals(Object other) {
PropertyValue otherPv = (PropertyValue) other;
return (this.name.equals(otherPv.name) &&
ObjectUtils.nullSafeEquals(this.value, otherPv.value) &&
ObjectUtils.nullSafeEquals(this.source, otherPv.source));
ObjectUtils.nullSafeEquals(getSource(), otherPv.getSource()));
}

@Override
Expand Down

0 comments on commit 5fe608d

Please sign in to comment.