From c0c9ba5c2cd7090d59d3e27e67dee9f088e4ccf5 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 31 Jan 2023 16:14:32 +0100 Subject: [PATCH] Polishing --- .../AbstractAdvisingBeanPostProcessor.java | 7 ++++--- .../factory/support/DisposableBeanAdapter.java | 17 ++++++++++------- .../event/ApplicationListenerMethodAdapter.java | 4 ++-- .../expression/spel/ast/MethodReference.java | 6 +++--- .../r2dbc/core/DefaultDatabaseClient.java | 4 +--- .../client/reactive/JettyClientHttpRequest.java | 5 ++--- .../web/servlet/DispatcherServlet.java | 1 + 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java index afde719ad3..1b021c7cd8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java @@ -93,12 +93,13 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSu if (bean instanceof Advised advised) { if (!advised.isFrozen() && isEligible(AopUtils.getTargetClass(bean))) { - // Add our local Advisor to the existing proxy's Advisor chain... + // Add our local Advisor to the existing proxy's Advisor chain. if (this.beforeExistingAdvisors) { advised.addAdvisor(0, this.advisor); } - else if (advised.getTargetSource() == AdvisedSupport.EMPTY_TARGET_SOURCE && advised.getAdvisorCount() > 0) { - // No target, leave last advisor in place + else if (advised.getTargetSource() == AdvisedSupport.EMPTY_TARGET_SOURCE && + advised.getAdvisorCount() > 0) { + // No target, leave last Advisor in place and add new Advisor right before. advised.addAdvisor(advised.getAdvisorCount() - 1, this.advisor); return bean; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java index 374e65aa0d..b073dc7a59 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -200,12 +200,15 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { ((DisposableBean) this.bean).destroy(); } catch (Throwable ex) { - String msg = "Invocation of destroy method failed on bean with name '" + this.beanName + "'"; - if (logger.isDebugEnabled()) { - logger.warn(msg, ex); - } - else { - logger.warn(msg + ": " + ex); + if (logger.isWarnEnabled()) { + String msg = "Invocation of destroy method failed on bean with name '" + this.beanName + "'"; + if (logger.isDebugEnabled()) { + // Log at warn level like below but add the exception stacktrace only with debug level + logger.warn(msg, ex); + } + else { + logger.warn(msg + ": " + ex); + } } } } diff --git a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java index 21d8ac7e87..0ad22b94d4 100644 --- a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java +++ b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -261,7 +261,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe return new Object[] {event}; } - @SuppressWarnings({ "deprecation", "unchecked" }) + @SuppressWarnings({"deprecation", "unchecked"}) protected void handleResult(Object result) { if (reactiveStreamsPresent && new ReactiveResultHandler().subscribeToPublisher(result)) { if (logger.isTraceEnabled()) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java index e9a896705f..4cd2615b22 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java @@ -263,7 +263,7 @@ public class MethodReference extends SpelNodeImpl { for (int i = 0; i < getChildCount(); i++) { sj.add(getChild(i).toStringAST()); } - return this.name + sj.toString(); + return this.name + sj; } /** @@ -283,12 +283,12 @@ public class MethodReference extends SpelNodeImpl { return false; } } - if (executor.didArgumentConversionOccur()) { return false; } + Class clazz = executor.getMethod().getDeclaringClass(); - return Modifier.isPublic(clazz.getModifiers()) || executor.getPublicDeclaringClass() != null; + return (Modifier.isPublic(clazz.getModifiers()) || executor.getPublicDeclaringClass() != null); } @Override diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java index 673bba5318..177c042f4d 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java @@ -166,7 +166,6 @@ class DefaultDatabaseClient implements DatabaseClient { * closed */ private Publisher closeConnection(Connection connection) { - return ConnectionFactoryUtils.currentConnectionFactory( obtainConnectionFactory()).then().onErrorResume(Exception.class, e -> Mono.from(connection.close())); @@ -192,8 +191,7 @@ class DefaultDatabaseClient implements DatabaseClient { new CloseSuppressingInvocationHandler(con)); } - private static Mono sumRowsUpdated( - Function> resultFunction, Connection it) { + private static Mono sumRowsUpdated(Function> resultFunction, Connection it) { return resultFunction.apply(it) .flatMap(Result::getRowsUpdated) .cast(Number.class) diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java index e2aa2f81a9..35e610f90f 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -94,8 +94,7 @@ class JettyClientHttpRequest extends AbstractClientHttpRequest { .as(chunks -> ReactiveRequest.Content.fromPublisher(chunks, getContentType())); this.builder.content(content); sink.success(); - }) - .then(doCommit()); + }).then(doCommit()); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index 934688c7ef..a5cca7b962 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -284,6 +284,7 @@ public class DispatcherServlet extends FrameworkServlet { */ private static final String DEFAULT_STRATEGIES_PREFIX = "org.springframework.web.servlet"; + /** Additional logger to use when no mapped handler is found for a request. */ protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY);