Defer initialization of HandlerMethod validation flags

Re-create the HandlerMethod only after the original is used as a key
in the CORS lookup map.

Closes gh-34375
This commit is contained in:
rstoyanchev
2025-02-07 13:10:33 +00:00
parent ff49b0b683
commit 84992536c5
2 changed files with 46 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -636,9 +636,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
HandlerMethod handlerMethod = createHandlerMethod(handler, method);
validateMethodMapping(handlerMethod, mapping);
// Enable method validation, if applicable
handlerMethod = handlerMethod.createWithValidateFlags();
Set<String> directPaths = AbstractHandlerMethodMapping.this.getDirectPaths(mapping);
for (String path : directPaths) {
this.pathLookup.add(path, mapping);
@@ -657,6 +654,10 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
this.corsLookup.put(handlerMethod, corsConfig);
}
// Init validation flags
// We do this strictly after using the original instance in the CORS lookups
handlerMethod = handlerMethod.createWithValidateFlags();
this.registry.put(mapping,
new MappingRegistration<>(mapping, handlerMethod, directPaths, name, corsConfig != null));
}