From 87b1b618fb7519abacbfb0e09302750511cbd181 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 12 Oct 2020 19:25:47 +0200 Subject: [PATCH] Polishing --- .../springframework/core/OrderComparator.java | 10 ++++++--- ...tractNamedValueMethodArgumentResolver.java | 7 ++++--- .../simp/stomp/DefaultStompSession.java | 8 ++----- ...tractNamedValueMethodArgumentResolver.java | 11 +++++----- .../MissingServletRequestPartException.java | 21 ++++++++++++------- .../AbstractNamedValueArgumentResolver.java | 8 +++---- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/OrderComparator.java b/spring-core/src/main/java/org/springframework/core/OrderComparator.java index f38f3923679..a478d6e0855 100644 --- a/spring-core/src/main/java/org/springframework/core/OrderComparator.java +++ b/spring-core/src/main/java/org/springframework/core/OrderComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -27,6 +27,10 @@ import org.springframework.util.ObjectUtils; * {@link Comparator} implementation for {@link Ordered} objects, sorting * by order value ascending, respectively by priority descending. * + *

{@code PriorityOrdered} Objects

+ *

{@link PriorityOrdered} objects will be sorted with higher priority than + * plain {@code Ordered} objects. + * *

Same Order Objects

*

Objects that have the same order value will be sorted with arbitrary * ordering with respect to other objects with the same order value. @@ -41,6 +45,7 @@ import org.springframework.util.ObjectUtils; * @author Sam Brannen * @since 07.04.2003 * @see Ordered + * @see PriorityOrdered * @see org.springframework.core.annotation.AnnotationAwareOrderComparator * @see java.util.List#sort(java.util.Comparator) * @see java.util.Arrays#sort(Object[], java.util.Comparator) @@ -96,8 +101,7 @@ public class OrderComparator implements Comparator { Object orderSource = sourceProvider.getOrderSource(obj); if (orderSource != null) { if (orderSource.getClass().isArray()) { - Object[] sources = ObjectUtils.toObjectArray(orderSource); - for (Object source : sources) { + for (Object source : ObjectUtils.toObjectArray(orderSource)) { order = findOrder(source); if (order != null) { break; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java index 486148260ab..b86164a1360 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -149,8 +149,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle if (info.name.isEmpty()) { name = parameter.getParameterName(); if (name == null) { - throw new IllegalArgumentException("Name for argument type [" + parameter.getParameterType().getName() + - "] not available, and parameter name information not found in class file either."); + throw new IllegalArgumentException( + "Name for argument of type [" + parameter.getNestedParameterType().getName() + + "] not specified, and parameter name information not found in class file either."); } } String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java index 7b782d6a0ee..487b24f42b4 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java @@ -111,7 +111,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { private final Map receiptHandlers = new ConcurrentHashMap<>(4); /* Whether the client is willfully closing the connection */ - private volatile boolean closing = false; + private volatile boolean closing; /** @@ -256,7 +256,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { private Message createMessage(StompHeaderAccessor accessor, @Nullable Object payload) { accessor.updateSimpMessageHeadersFromStompHeaders(); Message message; - if (isEmpty(payload)) { + if (StringUtils.isEmpty(payload) || (payload instanceof byte[] && ((byte[]) payload).length == 0)) { message = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders()); } else { @@ -271,10 +271,6 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { return message; } - private boolean isEmpty(@Nullable Object payload) { - return (StringUtils.isEmpty(payload) || (payload instanceof byte[] && ((byte[]) payload).length == 0)); - } - private void execute(Message message) { if (logger.isTraceEnabled()) { StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java index cc247ef510c..55ea38da9ef 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -131,7 +131,6 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle catch (TypeMismatchException ex) { throw new MethodArgumentTypeMismatchException(arg, ex.getRequiredType(), namedValueInfo.name, parameter, ex.getCause()); - } } @@ -170,8 +169,8 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle name = parameter.getParameterName(); if (name == null) { throw new IllegalArgumentException( - "Name for argument type [" + parameter.getNestedParameterType().getName() + - "] not available, and parameter name information not found in class file either."); + "Name for argument of type [" + parameter.getNestedParameterType().getName() + + "] not specified, and parameter name information not found in class file either."); } } String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue); @@ -184,12 +183,12 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle */ @Nullable private Object resolveStringValue(String value) { - if (this.configurableBeanFactory == null) { + if (this.configurableBeanFactory == null || this.expressionContext == null) { return value; } String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value); BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver(); - if (exprResolver == null || this.expressionContext == null) { + if (exprResolver == null) { return value; } return exprResolver.evaluate(placeholdersResolved, this.expressionContext); diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java b/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java index 62e1f1dee68..414405d8038 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 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. @@ -26,7 +26,7 @@ import org.springframework.web.multipart.MultipartResolver; * *

This may be because the request is not a multipart/form-data request, * because the part is not present in the request, or because the web - * application is not configured correctly for processing multipart requests, + * application is not configured correctly for processing multipart requests, * e.g. no {@link MultipartResolver}. * * @author Rossen Stoyanchev @@ -35,17 +35,24 @@ import org.springframework.web.multipart.MultipartResolver; @SuppressWarnings("serial") public class MissingServletRequestPartException extends ServletException { - private final String partName; + private final String requestPartName; - public MissingServletRequestPartException(String partName) { - super("Required request part '" + partName + "' is not present"); - this.partName = partName; + /** + * Constructor for MissingServletRequestPartException. + * @param requestPartName the name of the missing part of the multipart request + */ + public MissingServletRequestPartException(String requestPartName) { + super("Required request part '" + requestPartName + "' is not present"); + this.requestPartName = requestPartName; } + /** + * Return the name of the offending part of the multipart request. + */ public String getRequestPartName() { - return this.partName; + return this.requestPartName; } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueArgumentResolver.java index c7cd8e3af8c..9c0fb6021ea 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -144,9 +144,9 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr if (info.name.isEmpty()) { name = parameter.getParameterName(); if (name == null) { - String type = parameter.getNestedParameterType().getName(); - throw new IllegalArgumentException("Name for argument type [" + type + "] not " + - "available, and parameter name information not found in class file either."); + throw new IllegalArgumentException( + "Name for argument of type [" + parameter.getNestedParameterType().getName() + + "] not specified, and parameter name information not found in class file either."); } } String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);