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