Skip to content

Commit 9ece4a8

Browse files
author
Keith Donald
committed
perform narrowing in reflective property accessor read methods as well
1 parent c306afe commit 9ece4a8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ public TypedValue read(EvaluationContext context, Object target, String name) th
138138
if (method != null) {
139139
try {
140140
ReflectionUtils.makeAccessible(method);
141-
return new TypedValue(method.invoke(target),invoker.typeDescriptor);
141+
Object value = method.invoke(target);
142+
return new TypedValue(value, invoker.typeDescriptor.narrow(value));
142143
}
143144
catch (Exception ex) {
144145
throw new AccessException("Unable to access property '" + name + "' through getter", ex);
@@ -147,7 +148,7 @@ public TypedValue read(EvaluationContext context, Object target, String name) th
147148
}
148149

149150
if (invoker == null || invoker.member instanceof Field) {
150-
Field field = (Field) (invoker==null?null:invoker.member);
151+
Field field = (Field) (invoker == null ? null : invoker.member);
151152
if (field == null) {
152153
field = findField(name, type, target instanceof Class);
153154
if (field != null) {
@@ -158,7 +159,8 @@ public TypedValue read(EvaluationContext context, Object target, String name) th
158159
if (field != null) {
159160
try {
160161
ReflectionUtils.makeAccessible(field);
161-
return new TypedValue(field.get(target),invoker.typeDescriptor);
162+
Object value = field.get(target);
163+
return new TypedValue(value, invoker.typeDescriptor.narrow(value));
162164
}
163165
catch (Exception ex) {
164166
throw new AccessException("Unable to access field: " + name, ex);
@@ -183,7 +185,7 @@ public boolean canWrite(EvaluationContext context, Object target, String name) t
183185
// Treat it like a property
184186
PropertyDescriptor propertyDescriptor = null;
185187
try {
186-
propertyDescriptor = new PropertyDescriptor(name,null,method);
188+
propertyDescriptor = new PropertyDescriptor(name, null, method);
187189
}
188190
catch (IntrospectionException ex) {
189191
throw new AccessException("Unable to access property '" + name + "' through setter "+method, ex);

0 commit comments

Comments
 (0)