Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpEL: cannot call methods declared in java.lang.Object on a JDK proxy #25316

Closed
wants to merge 1 commit into from

Conversation

MrCoffee77
Copy link

@MrCoffee77 MrCoffee77 commented Jun 25, 2020

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

Make sure to have methods of Object on Proxy-Objects.
@pivotal-issuemaster
Copy link

@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.

@pivotal-issuemaster
Copy link

@MrCoffee77 Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 25, 2020
@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 10, 2021
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per Code-Style#import-statements we should avoid wildcard imports.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. We do not use wildcard imports for types.

@sbrannen sbrannen changed the title #23369 SpEL: cannot call methods from Object on a proxy Mar 14, 2023
Copy link
Member

@sbrannen sbrannen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sbrannen sbrannen self-assigned this Mar 14, 2023
@sbrannen sbrannen added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 14, 2023
@sbrannen sbrannen changed the title SpEL: cannot call methods from Object on a proxy SpEL: cannot call methods declared in java.lang.Object on a JDK proxy Mar 14, 2023
@sbrannen sbrannen added the status: backported An issue that has been backported to maintenance branches label Mar 14, 2023
@sbrannen sbrannen added this to the 6.0.7 milestone Mar 14, 2023
@sbrannen sbrannen closed this in 97b5af8 Mar 14, 2023
sbrannen added a commit to sbrannen/spring-framework that referenced this pull request Mar 14, 2023
@sbrannen
Copy link
Member

Hi @MrCoffee77,

Congratulations on having your first pull request for the Spring Framework accepted! 👍

This has been merged into main in 97b5af8 and revised in 1de36ab.

This will also be backported to 5.3.x.

Thanks

sbrannen pushed a commit that referenced this pull request Mar 15, 2023
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
sbrannen added a commit that referenced this pull request Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants