Skip to content

Commit 898494a

Browse files
committed
Polish AbstractHandlerMethodMapping
See gh-22543
1 parent d04a640 commit 898494a

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,7 @@ public void register(T mapping, Object handler, Method method) {
589589
this.readWriteLock.writeLock().lock();
590590
try {
591591
HandlerMethod handlerMethod = createHandlerMethod(handler, method);
592-
assertMappedPathMethodMapping(handlerMethod, mapping);
593-
assertUniqueMethodMapping(handlerMethod, mapping);
592+
validateMethodMapping(handlerMethod, mapping);
594593
this.mappingLookup.put(mapping, handlerMethod);
595594

596595
List<String> directUrls = getDirectUrls(mapping);
@@ -616,28 +615,23 @@ public void register(T mapping, Object handler, Method method) {
616615
}
617616
}
618617

619-
/**
620-
* Assert that the supplied {@code mapping} maps the supplied {@link HandlerMethod}
621-
* to explicit, non-empty paths.
622-
* @since 5.2
623-
* @see StringUtils#hasText(String)
624-
*/
625-
private void assertMappedPathMethodMapping(HandlerMethod handlerMethod, T mapping) {
618+
private void validateMethodMapping(HandlerMethod handlerMethod, T mapping) {
619+
// Assert that the supplied mapping maps the supplied HandlerMethod
620+
// to explicit, non-empty paths.
626621
if (!getMappingPathPatterns(mapping).stream().allMatch(StringUtils::hasText)) {
627622
throw new IllegalStateException(String.format("Missing path mapping. " +
628623
"Handler method '%s' in bean '%s' must be mapped to a non-empty path. " +
629624
"If you wish to map to all paths, please map explicitly to \"/**\" or \"**\".",
630-
handlerMethod, handlerMethod.getBean()));
625+
handlerMethod, handlerMethod.getBean()));
631626
}
632-
}
633627

634-
private void assertUniqueMethodMapping(HandlerMethod newHandlerMethod, T mapping) {
635-
HandlerMethod handlerMethod = this.mappingLookup.get(mapping);
636-
if (handlerMethod != null && !handlerMethod.equals(newHandlerMethod)) {
628+
// Assert that the supplied mapping is unique.
629+
HandlerMethod existingHandlerMethod = this.mappingLookup.get(mapping);
630+
if (existingHandlerMethod != null && !existingHandlerMethod.equals(handlerMethod)) {
637631
throw new IllegalStateException(
638-
"Ambiguous mapping. Cannot map '" + newHandlerMethod.getBean() + "' method \n" +
639-
newHandlerMethod + "\nto " + mapping + ": There is already '" +
640-
handlerMethod.getBean() + "' bean method\n" + handlerMethod + " mapped.");
632+
"Ambiguous mapping. Cannot map '" + handlerMethod.getBean() + "' method \n" +
633+
handlerMethod + "\nto " + mapping + ": There is already '" +
634+
existingHandlerMethod.getBean() + "' bean method\n" + existingHandlerMethod + " mapped.");
641635
}
642636
}
643637

0 commit comments

Comments
 (0)