Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public boolean canRead(EvaluationContext context, @Nullable Object target, Strin
if (method != null) {
// Treat it like a property...
// The readerCache will only contain gettable properties (let's not worry about setters for now).
Property property = new Property(type, method, null);
Property property = new Property(type, method, null, name);
TypeDescriptor typeDescriptor = new TypeDescriptor(property);
Method methodToInvoke = ClassUtils.getPubliclyAccessibleMethodIfPossible(method, type);
this.readerCache.put(cacheKey, new InvokerPair(methodToInvoke, typeDescriptor));
Expand Down Expand Up @@ -193,7 +193,7 @@ public TypedValue read(EvaluationContext context, @Nullable Object target, Strin
if (method != null) {
// Treat it like a property...
// The readerCache will only contain gettable properties (let's not worry about setters for now).
Property property = new Property(type, method, null);
Property property = new Property(type, method, null, name);
TypeDescriptor typeDescriptor = new TypeDescriptor(property);
methodToInvoke = ClassUtils.getPubliclyAccessibleMethodIfPossible(method, type);
invoker = new InvokerPair(methodToInvoke, typeDescriptor);
Expand Down Expand Up @@ -251,7 +251,7 @@ public boolean canWrite(EvaluationContext context, @Nullable Object target, Stri
Method method = findSetterForProperty(name, type, target);
if (method != null) {
// Treat it like a property
Property property = new Property(type, null, method);
Property property = new Property(type, null, method, name);
TypeDescriptor typeDescriptor = new TypeDescriptor(property);
method = ClassUtils.getPubliclyAccessibleMethodIfPossible(method, type);
this.writerCache.put(cacheKey, method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ void propertyAccessWithArrayIndexOutOfBounds() {
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.ARRAY_INDEX_OUT_OF_BOUNDS);
}

@Test
void propertyAccessorUtilizesKnownPropertyName() {
StandardEvaluationContext context = new StandardEvaluationContext(new Inventor("Nikola Tesla"));
Expression expression = parser.parseExpression("name");

// This triggers ReflectivePropertyAccessor getter resolution and caching (reads)
Object value = expression.getValue(context);
assertThat(value).isEqualTo("Nikola Tesla");

// This triggers ReflectivePropertyAccessor setter resolution and caching (writes)
assertThat(expression.isWritable(context)).isTrue();
expression.setValue(context, "New Name");
assertThat(expression.getValue(context)).isEqualTo("New Name");
}


private ThrowableTypeAssert<SpelEvaluationException> assertThatSpelEvaluationException() {
return assertThatExceptionOfType(SpelEvaluationException.class);
Expand Down