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

Improve AnnotatedMethod#equals and HandlerMethod CORS lookups #34375

Closed
rstoyanchev opened this issue Feb 6, 2025 · 0 comments
Closed

Improve AnnotatedMethod#equals and HandlerMethod CORS lookups #34375

rstoyanchev opened this issue Feb 6, 2025 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

After #34277, lookups by HandlerMethod for CORS configuration began to fail for HandlerMethod extensions like Boot's WebMvcEndpointHandlerMethod. There are several aspects.

First, when a HandlerMethod is registered, it is used as a key to store its CORS config. At runtime the HandlerMethod is re-created to resolve the handler from a bean name, and we also store the original HandlerMethod to still be able to lookup CORS config.

When HandlerMethod validation was added, we began to also re-create the HandlerMethod before the CORS config registration, resulting in the wrapper being the key rather than the original. This went unnoticed because the handler and the Method are used in the hashcode() and equals() implementations so the actual instance matters less. However, AnnotatedMethod#equals does a Class equality check, which breaks Map lookups for custom HandlerMethod classes, and also makes hashcode and equals out of sync in that case.

This issue surfaced after we stopped re-creating HandlerMethod's at runtime in #34277 if the handler is not a bean name, but an actual instance, and this broke a Boot test that registers a custom HandlerMethod.

We need to fix the AnnotatedMethod#equals and revisit how we look up CORS config for HandlerMethod for an improvement.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug type: enhancement A general enhancement labels Feb 6, 2025
@rstoyanchev rstoyanchev added this to the 7.0.0-M2 milestone Feb 6, 2025
@rstoyanchev rstoyanchev self-assigned this Feb 6, 2025
rstoyanchev added a commit that referenced this issue Feb 7, 2025
Ensure the original instance is always the one returned no matter how
many times the HandlerMethod is re-created.

Make the constructor protected to allow subclasses to re-create the
HandlerMethod as the concrete subclass.

See gh-34375
@snicoll snicoll removed the type: bug A general bug label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants