SpEL: cannot call methods declared in java.lang.Object on a JDK proxy#25316
SpEL: cannot call methods declared in java.lang.Object on a JDK proxy#25316MrCoffee77 wants to merge 1 commit intospring-projects:mainfrom
java.lang.Object on a JDK proxy#25316Conversation
Make sure to have methods of Object on Proxy-Objects.
|
@MrCoffee77 Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
|
@MrCoffee77 Thank you for signing the Contributor License Agreement! |
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.*; |
There was a problem hiding this comment.
As per Code-Style#import-statements we should avoid wildcard imports.
There was a problem hiding this comment.
That's correct. We do not use wildcard imports for types.
sbrannen
left a comment
There was a problem hiding this comment.
Thanks for the PR!
And... sorry for taking so long to process this.
I've left a few comments that are intended to be informational. There is no need to modify this PR to make the suggested changes.
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.*; |
There was a problem hiding this comment.
That's correct. We do not use wildcard imports for types.
| methods.addAll(Arrays.asList(Object.class.getMethods())); | ||
|
|
||
| Method[] methods1 = methods.toArray(new Method[0]); | ||
| return methods1; |
There was a problem hiding this comment.
I think it would be better to make a change specific to JDK proxies in getMethods(Class<?>, Object) instead of having this change globally applied in getMethods(Class<?>).
However, there is no need to modify this PR.
I already have such a change in place locally and will apply that when merging your PR.
| } | ||
| }); | ||
| MethodExecutor mexec=resolver.resolve(evaluationContext,obj,"toString",new ArrayList<>()); | ||
| Assert.notNull(mexec,"MethodExecutor should not be empty."); |
There was a problem hiding this comment.
We use AssertJ for test assertions, not Spring's org.springframework.util.Assert class.
In any case, I'll make that change when merging the PR.
java.lang.Object on a JDK proxy
|
Hi @MrCoffee77, Congratulations on having your first pull request for the Spring Framework accepted! 👍 This has been merged into This will also be backported to Thanks |
This commit ensures that methods declared in java.lang.Object (such as toString() can be invoked on a JDK proxy instance in a SpEL expression. Closes gh-25316
Hello, I built a fix for my problem with SpEL and proxy objects as described in #23369.
Now I want to contribute my changes.
Regards
Florian