Skip to content

Commit 217aa38

Browse files
committed
Polishing
1 parent 2474c48 commit 217aa38

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ public InitBinderDataBinderFactory(@Nullable List<InvocableHandlerMethod> binder
5353
this.binderMethods = (binderMethods != null ? binderMethods : Collections.emptyList());
5454
}
5555

56+
5657
/**
5758
* Initialize a WebDataBinder with {@code @InitBinder} methods.
5859
* <p>If the {@code @InitBinder} annotation specifies attributes names,
5960
* it is invoked only if the names include the target object name.
60-
* @throws Exception if one of the invoked @{@link InitBinder} methods fail.
61+
* @throws Exception if one of the invoked @{@link InitBinder} methods fails
62+
* @see #isBinderMethodApplicable
6163
*/
6264
@Override
6365
public void initBinder(WebDataBinder dataBinder, NativeWebRequest request) throws Exception {
@@ -66,19 +68,19 @@ public void initBinder(WebDataBinder dataBinder, NativeWebRequest request) throw
6668
Object returnValue = binderMethod.invokeForRequest(request, null, dataBinder);
6769
if (returnValue != null) {
6870
throw new IllegalStateException(
69-
"@InitBinder methods should return void: " + binderMethod);
71+
"@InitBinder methods must not return a value (should be void): " + binderMethod);
7072
}
7173
}
7274
}
7375
}
7476

7577
/**
76-
* Whether the given {@code @InitBinder} method should be used to initialize
77-
* the given WebDataBinder instance. By default we check the attributes
78-
* names of the annotation, if present.
78+
* Determine whether the given {@code @InitBinder} method should be used
79+
* to initialize the given {@link WebDataBinder} instance. By default we
80+
* check the specified attribute names in the annotation value, if any.
7981
*/
80-
protected boolean isBinderMethodApplicable(HandlerMethod binderMethod, WebDataBinder dataBinder) {
81-
InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class);
82+
protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder dataBinder) {
83+
InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class);
8284
Assert.state(ann != null, "No InitBinder annotation");
8385
String[] names = ann.value();
8486
return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName()));

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ protected WebExchangeDataBinder initDataBinder(WebExchangeDataBinder dataBinder,
8383
return dataBinder;
8484
}
8585

86-
private void invokeBinderMethod(WebExchangeDataBinder dataBinder, ServerWebExchange exchange,
87-
SyncInvocableHandlerMethod binderMethod) {
86+
private void invokeBinderMethod(
87+
WebExchangeDataBinder dataBinder, ServerWebExchange exchange, SyncInvocableHandlerMethod binderMethod) {
8888

8989
HandlerResult result = binderMethod.invokeForHandlerResult(exchange, this.binderMethodContext, dataBinder);
9090
if (result != null && result.getReturnValue() != null) {
9191
throw new IllegalStateException(
92-
"@InitBinder methods should return void: " + binderMethod);
92+
"@InitBinder methods must not return a value (should be void): " + binderMethod);
9393
}
9494
// Should not happen (no Model argument resolution) ...
9595
if (!this.binderMethodContext.getModel().asMap().isEmpty()) {
9696
throw new IllegalStateException(
97-
"@InitBinder methods should not add model attributes: " + binderMethod);
97+
"@InitBinder methods are not allowed to add model attributes: " + binderMethod);
9898
}
9999
}
100100

0 commit comments

Comments
 (0)