From 217aa38cbb86596118cdd3d53aa33ce037911929 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 2 Aug 2018 17:45:46 +0200 Subject: [PATCH] Polishing --- .../annotation/InitBinderDataBinderFactory.java | 16 +++++++++------- .../annotation/InitBinderBindingContext.java | 8 ++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java b/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java index f6085d95aa..648fe94134 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java @@ -53,11 +53,13 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory { this.binderMethods = (binderMethods != null ? binderMethods : Collections.emptyList()); } + /** * Initialize a WebDataBinder with {@code @InitBinder} methods. *

If the {@code @InitBinder} annotation specifies attributes names, * it is invoked only if the names include the target object name. - * @throws Exception if one of the invoked @{@link InitBinder} methods fail. + * @throws Exception if one of the invoked @{@link InitBinder} methods fails + * @see #isBinderMethodApplicable */ @Override public void initBinder(WebDataBinder dataBinder, NativeWebRequest request) throws Exception { @@ -66,19 +68,19 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory { Object returnValue = binderMethod.invokeForRequest(request, null, dataBinder); if (returnValue != null) { throw new IllegalStateException( - "@InitBinder methods should return void: " + binderMethod); + "@InitBinder methods must not return a value (should be void): " + binderMethod); } } } } /** - * Whether the given {@code @InitBinder} method should be used to initialize - * the given WebDataBinder instance. By default we check the attributes - * names of the annotation, if present. + * Determine whether the given {@code @InitBinder} method should be used + * to initialize the given {@link WebDataBinder} instance. By default we + * check the specified attribute names in the annotation value, if any. */ - protected boolean isBinderMethodApplicable(HandlerMethod binderMethod, WebDataBinder dataBinder) { - InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class); + protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder dataBinder) { + InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class); Assert.state(ann != null, "No InitBinder annotation"); String[] names = ann.value(); return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName())); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java index 85e3f20ac8..0c6c8c07d2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java @@ -83,18 +83,18 @@ class InitBinderBindingContext extends BindingContext { return dataBinder; } - private void invokeBinderMethod(WebExchangeDataBinder dataBinder, ServerWebExchange exchange, - SyncInvocableHandlerMethod binderMethod) { + private void invokeBinderMethod( + WebExchangeDataBinder dataBinder, ServerWebExchange exchange, SyncInvocableHandlerMethod binderMethod) { HandlerResult result = binderMethod.invokeForHandlerResult(exchange, this.binderMethodContext, dataBinder); if (result != null && result.getReturnValue() != null) { throw new IllegalStateException( - "@InitBinder methods should return void: " + binderMethod); + "@InitBinder methods must not return a value (should be void): " + binderMethod); } // Should not happen (no Model argument resolution) ... if (!this.binderMethodContext.getModel().asMap().isEmpty()) { throw new IllegalStateException( - "@InitBinder methods should not add model attributes: " + binderMethod); + "@InitBinder methods are not allowed to add model attributes: " + binderMethod); } }