Skip to content

Commit 66a67ec

Browse files
committed
Polishing
1 parent 69c330d commit 66a67ec

File tree

7 files changed

+39
-40
lines changed

7 files changed

+39
-40
lines changed

spring-core/src/main/java/org/springframework/core/OrderComparator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -101,8 +101,7 @@ private int getOrder(@Nullable Object obj, @Nullable OrderSourceProvider sourceP
101101
Object orderSource = sourceProvider.getOrderSource(obj);
102102
if (orderSource != null) {
103103
if (orderSource.getClass().isArray()) {
104-
Object[] sources = ObjectUtils.toObjectArray(orderSource);
105-
for (Object source : sources) {
104+
for (Object source : ObjectUtils.toObjectArray(orderSource)) {
106105
order = findOrder(source);
107106
if (order != null) {
108107
break;

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/AbstractNamedValueMethodArgumentResolver.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,7 +82,6 @@ protected AbstractNamedValueMethodArgumentResolver(ConversionService conversionS
8282

8383
@Override
8484
public Object resolveArgumentValue(MethodParameter parameter, Message<?> message) {
85-
8685
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
8786
MethodParameter nestedParameter = parameter.nestedIfOptional();
8887

@@ -144,10 +143,9 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu
144143
if (info.name.isEmpty()) {
145144
name = parameter.getParameterName();
146145
if (name == null) {
147-
Class<?> type = parameter.getParameterType();
148146
throw new IllegalArgumentException(
149-
"Name for argument of type [" + type.getName() + "] not specified, " +
150-
"and parameter name information not found in class file either.");
147+
"Name for argument of type [" + parameter.getNestedParameterType().getName() +
148+
"] not specified, and parameter name information not found in class file either.");
151149
}
152150
}
153151
return new NamedValueInfo(name, info.required,

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,8 +80,8 @@ protected AbstractNamedValueMethodArgumentResolver(ConversionService conversionS
8080
// Possibly remove after discussion in gh-23882.
8181

8282
//noinspection ConstantConditions
83-
this.conversionService = conversionService != null ?
84-
conversionService : DefaultConversionService.getSharedInstance();
83+
this.conversionService = (conversionService != null ?
84+
conversionService : DefaultConversionService.getSharedInstance());
8585

8686
this.configurableBeanFactory = beanFactory;
8787
this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, null) : null);
@@ -154,10 +154,9 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu
154154
if (info.name.isEmpty()) {
155155
name = parameter.getParameterName();
156156
if (name == null) {
157-
Class<?> type = parameter.getParameterType();
158157
throw new IllegalArgumentException(
159-
"Name for argument of type [" + type.getName() + "] not specified, " +
160-
"and parameter name information not found in class file either.");
158+
"Name for argument of type [" + parameter.getNestedParameterType().getName() +
159+
"] not specified, and parameter name information not found in class file either.");
161160
}
162161
}
163162
return new NamedValueInfo(name, info.required,

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
111111
private final Map<String, ReceiptHandler> receiptHandlers = new ConcurrentHashMap<>(4);
112112

113113
/* Whether the client is willfully closing the connection */
114-
private volatile boolean closing = false;
114+
private volatile boolean closing;
115115

116116

117117
/**
@@ -256,7 +256,7 @@ private StompHeaderAccessor createHeaderAccessor(StompCommand command) {
256256
private Message<byte[]> createMessage(StompHeaderAccessor accessor, @Nullable Object payload) {
257257
accessor.updateSimpMessageHeadersFromStompHeaders();
258258
Message<byte[]> message;
259-
if (isEmpty(payload)) {
259+
if (StringUtils.isEmpty(payload) || (payload instanceof byte[] && ((byte[]) payload).length == 0)) {
260260
message = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
261261
}
262262
else {
@@ -271,10 +271,6 @@ private Message<byte[]> createMessage(StompHeaderAccessor accessor, @Nullable Ob
271271
return message;
272272
}
273273

274-
private boolean isEmpty(@Nullable Object payload) {
275-
return (StringUtils.isEmpty(payload) || (payload instanceof byte[] && ((byte[]) payload).length == 0));
276-
}
277-
278274
private void execute(Message<byte[]> message) {
279275
if (logger.isTraceEnabled()) {
280276
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,7 +99,7 @@ public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAn
9999
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
100100
MethodParameter nestedParameter = parameter.nestedIfOptional();
101101

102-
Object resolvedName = resolveStringValue(namedValueInfo.name);
102+
Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
103103
if (resolvedName == null) {
104104
throw new IllegalArgumentException(
105105
"Specified name must not resolve to null: [" + namedValueInfo.name + "]");
@@ -108,15 +108,15 @@ public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAn
108108
Object arg = resolveName(resolvedName.toString(), nestedParameter, webRequest);
109109
if (arg == null) {
110110
if (namedValueInfo.defaultValue != null) {
111-
arg = resolveStringValue(namedValueInfo.defaultValue);
111+
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
112112
}
113113
else if (namedValueInfo.required && !nestedParameter.isOptional()) {
114114
handleMissingValue(namedValueInfo.name, nestedParameter, webRequest);
115115
}
116116
arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType());
117117
}
118118
else if ("".equals(arg) && namedValueInfo.defaultValue != null) {
119-
arg = resolveStringValue(namedValueInfo.defaultValue);
119+
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
120120
}
121121

122122
if (binderFactory != null) {
@@ -169,8 +169,8 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu
169169
name = parameter.getParameterName();
170170
if (name == null) {
171171
throw new IllegalArgumentException(
172-
"Name for argument type [" + parameter.getNestedParameterType().getName() +
173-
"] not available, and parameter name information not found in class file either.");
172+
"Name for argument of type [" + parameter.getNestedParameterType().getName() +
173+
"] not specified, and parameter name information not found in class file either.");
174174
}
175175
}
176176
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
@@ -182,13 +182,13 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu
182182
* potentially containing placeholders and expressions.
183183
*/
184184
@Nullable
185-
private Object resolveStringValue(String value) {
186-
if (this.configurableBeanFactory == null) {
185+
private Object resolveEmbeddedValuesAndExpressions(String value) {
186+
if (this.configurableBeanFactory == null || this.expressionContext == null) {
187187
return value;
188188
}
189189
String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
190190
BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
191-
if (exprResolver == null || this.expressionContext == null) {
191+
if (exprResolver == null) {
192192
return value;
193193
}
194194
return exprResolver.evaluate(placeholdersResolved, this.expressionContext);

spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@
2626
*
2727
* <p>This may be because the request is not a multipart/form-data request,
2828
* because the part is not present in the request, or because the web
29-
* application is not configured correctly for processing multipart requests,
29+
* application is not configured correctly for processing multipart requests,
3030
* e.g. no {@link MultipartResolver}.
3131
*
3232
* @author Rossen Stoyanchev
@@ -35,17 +35,24 @@
3535
@SuppressWarnings("serial")
3636
public class MissingServletRequestPartException extends ServletException {
3737

38-
private final String partName;
38+
private final String requestPartName;
3939

4040

41-
public MissingServletRequestPartException(String partName) {
42-
super("Required request part '" + partName + "' is not present");
43-
this.partName = partName;
41+
/**
42+
* Constructor for MissingServletRequestPartException.
43+
* @param requestPartName the name of the missing part of the multipart request
44+
*/
45+
public MissingServletRequestPartException(String requestPartName) {
46+
super("Required request part '" + requestPartName + "' is not present");
47+
this.requestPartName = requestPartName;
4448
}
4549

4650

51+
/**
52+
* Return the name of the offending part of the multipart request.
53+
*/
4754
public String getRequestPartName() {
48-
return this.partName;
55+
return this.requestPartName;
4956
}
5057

5158
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -144,9 +144,9 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu
144144
if (info.name.isEmpty()) {
145145
name = parameter.getParameterName();
146146
if (name == null) {
147-
String type = parameter.getNestedParameterType().getName();
148-
throw new IllegalArgumentException("Name for argument type [" + type + "] not " +
149-
"available, and parameter name information not found in class file either.");
147+
throw new IllegalArgumentException(
148+
"Name for argument of type [" + parameter.getNestedParameterType().getName() +
149+
"] not specified, and parameter name information not found in class file either.");
150150
}
151151
}
152152
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);

0 commit comments

Comments
 (0)