From 72b2dda17fcdb43af14778597da0c92970143b80 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 13 Oct 2020 00:20:06 +0200 Subject: [PATCH 1/2] Avoid creation of unused logger instance in AbstractMediaTypeExpression Closes gh-25901 --- .../result/condition/AbstractMediaTypeExpression.java | 7 +------ .../method/HandlerMethodArgumentResolverComposite.java | 4 ---- .../servlet/mvc/condition/AbstractMediaTypeExpression.java | 7 +------ 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java index a9667a3604..63a9be4239 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.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. @@ -16,9 +16,6 @@ package org.springframework.web.reactive.result.condition; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.http.MediaType; import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestMapping; @@ -35,8 +32,6 @@ import org.springframework.web.server.UnsupportedMediaTypeStatusException; */ abstract class AbstractMediaTypeExpression implements Comparable, MediaTypeExpression { - protected final Log logger = LogFactory.getLog(getClass()); - private final MediaType mediaType; private final boolean isNegated; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java index 1161c1c8e4..46baa13c5f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java @@ -22,8 +22,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; @@ -41,8 +39,6 @@ import org.springframework.web.server.ServerWebExchange; */ class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentResolver { - protected final Log logger = LogFactory.getLog(getClass()); - private final List argumentResolvers = new ArrayList<>(); private final Map argumentResolverCache = diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java index 6921863f65..0b3c631993 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.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. @@ -16,9 +16,6 @@ package org.springframework.web.servlet.mvc.condition; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.http.MediaType; import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestMapping; @@ -33,8 +30,6 @@ import org.springframework.web.bind.annotation.RequestMapping; */ abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Comparable { - protected final Log logger = LogFactory.getLog(getClass()); - private final MediaType mediaType; private final boolean isNegated; From f3f19504c65eb679b6eeb16c83781f887b96e155 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 13 Oct 2020 00:21:07 +0200 Subject: [PATCH 2/2] Polishing --- ...dlerMethodReturnValueHandlerComposite.java | 3 +- .../invocation/reactive/InvocableHelper.java | 4 +-- .../support/InvocableHandlerMethod.java | 28 +++++++++---------- .../result/method/InvocableHandlerMethod.java | 9 +++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandlerComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandlerComposite.java index 08569163e3..c9347256b0 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandlerComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandlerComposite.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. @@ -38,7 +38,6 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe protected final Log logger = LogFactory.getLog(getClass()); - private final List returnValueHandlers = new ArrayList<>(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/InvocableHelper.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/InvocableHelper.java index d4ba44d4a4..411a295bf5 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/InvocableHelper.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/InvocableHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 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. @@ -46,7 +46,7 @@ import org.springframework.util.Assert; */ class InvocableHelper { - private static Log logger = LogFactory.getLog(InvocableHelper.class); + private static final Log logger = LogFactory.getLog(InvocableHelper.class); private final HandlerMethodArgumentResolverComposite argumentResolvers = diff --git a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java index e5c71b44f3..817a4f2935 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 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. @@ -46,13 +46,13 @@ public class InvocableHandlerMethod extends HandlerMethod { private static final Object[] EMPTY_ARGS = new Object[0]; - @Nullable - private WebDataBinderFactory dataBinderFactory; - private HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite(); private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); + @Nullable + private WebDataBinderFactory dataBinderFactory; + /** * Create an instance from a {@code HandlerMethod}. @@ -83,16 +83,8 @@ public class InvocableHandlerMethod extends HandlerMethod { /** - * Set the {@link WebDataBinderFactory} to be passed to argument resolvers allowing them to create - * a {@link WebDataBinder} for data binding and type conversion purposes. - * @param dataBinderFactory the data binder factory. - */ - public void setDataBinderFactory(WebDataBinderFactory dataBinderFactory) { - this.dataBinderFactory = dataBinderFactory; - } - - /** - * Set {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers} to use to use for resolving method argument values. + * Set {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers} + * to use for resolving method argument values. */ public void setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers) { this.resolvers = argumentResolvers; @@ -107,6 +99,14 @@ public class InvocableHandlerMethod extends HandlerMethod { this.parameterNameDiscoverer = parameterNameDiscoverer; } + /** + * Set the {@link WebDataBinderFactory} to be passed to argument resolvers allowing them + * to create a {@link WebDataBinder} for data binding and type conversion purposes. + */ + public void setDataBinderFactory(WebDataBinderFactory dataBinderFactory) { + this.dataBinderFactory = dataBinderFactory; + } + /** * Invoke the method after resolving its argument values in the context of the given request. diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java index c419fb491e..cc3c5841ba 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 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. @@ -60,7 +60,7 @@ public class InvocableHandlerMethod extends HandlerMethod { private static final Object NO_ARG_VALUE = new Object(); - private HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite(); + private final HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite(); private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); @@ -139,8 +139,9 @@ public class InvocableHandlerMethod extends HandlerMethod { try { ReflectionUtils.makeAccessible(getBridgedMethod()); Method method = getBridgedMethod(); - if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(method.getDeclaringClass()) - && CoroutinesUtils.isSuspendingFunction(method)) { + if (KotlinDetector.isKotlinReflectPresent() && + KotlinDetector.isKotlinType(method.getDeclaringClass()) && + CoroutinesUtils.isSuspendingFunction(method)) { value = CoroutinesUtils.invokeSuspendingFunction(method, getBean(), args); } else {