Add targetIsClass to SpEL property cache key

Update the `CacheKey` class used by `ReflectivePropertyAccessor` to
include if the target object is class. The prevents an incorrect cache
hit from being returned when a property with the same name is read on
both an object and its class. For example:

	#{class.name}
	#{name}

Issue: SPR-10486
(cherry picked from commit 6d882b14)
This commit is contained in:
Phillip Webb
2013-10-21 10:54:49 -07:00
parent 1ea7f741fe
commit 5854d519a1
2 changed files with 51 additions and 8 deletions

View File

@@ -1818,6 +1818,19 @@ public class SpelReproTests extends ExpressionTestCase {
assertEquals(XYZ.Z, Array.get(result, 2));
}
@Test
public void SPR_10486() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
SPR10486 rootObject = new SPR10486();
Expression classNameExpression = parser.parseExpression("class.name");
Expression nameExpression = parser.parseExpression("name");
assertThat(classNameExpression.getValue(context, rootObject),
equalTo((Object) SPR10486.class.getName()));
assertThat(nameExpression.getValue(context, rootObject),
equalTo((Object) "name"));
}
private static enum ABC {A, B, C}
@@ -1885,4 +1898,20 @@ public class SpelReproTests extends ExpressionTestCase {
public static class StaticFinalImpl2 extends AbstractStaticFinal {
}
/**
* The Class TestObject.
*/
public static class SPR10486 {
private String name = "name";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}