From 42e7318cbbaf4d8e461bf2789058a797995b7043 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 31 Jan 2023 16:48:36 +0100 Subject: [PATCH] Polishing --- .../support/DisposableBeanAdapter.java | 49 +++++++++++-------- .../beans/BeanWrapperTests.java | 1 + .../expression/spel/ast/MethodReference.java | 11 ++--- .../r2dbc/core/DefaultDatabaseClient.java | 27 +++++----- .../reactive/JettyClientHttpRequest.java | 3 +- .../web/servlet/DispatcherServlet.java | 3 +- 6 files changed, 48 insertions(+), 46 deletions(-) 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 4317ae901c9..3510fb95ce1 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. @@ -214,12 +214,15 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { } } 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); + } } } } @@ -240,12 +243,15 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { } } catch (Throwable ex) { - String msg = "Invocation of close 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 close 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); + } } } } @@ -320,13 +326,16 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { } } catch (InvocationTargetException ex) { - String msg = "Custom destroy method '" + this.destroyMethodName + "' on bean with name '" + - this.beanName + "' threw an exception"; - if (logger.isDebugEnabled()) { - logger.warn(msg, ex.getTargetException()); - } - else { - logger.warn(msg + ": " + ex.getTargetException()); + if (logger.isWarnEnabled()) { + String msg = "Custom destroy method '" + this.destroyMethodName + "' on bean with name '" + + this.beanName + "' threw an exception"; + if (logger.isDebugEnabled()) { + // Log at warn level like below but add the exception stacktrace only with debug level + logger.warn(msg, ex.getTargetException()); + } + else { + logger.warn(msg + ": " + ex.getTargetException()); + } } } catch (Throwable ex) { diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java index 5011797666d..c933699da38 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java @@ -395,6 +395,7 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests { } + @SuppressWarnings("try") public static class ActiveResource implements AutoCloseable { public ActiveResource getResource() { 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 1ecb6187001..2e3b6404b92 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. @@ -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; } /** @@ -288,12 +288,9 @@ public class MethodReference extends SpelNodeImpl { if (executor.didArgumentConversionOccur()) { return false; } - Class clazz = executor.getMethod().getDeclaringClass(); - if (!Modifier.isPublic(clazz.getModifiers()) && executor.getPublicDeclaringClass() == null) { - return false; - } - return true; + Class clazz = executor.getMethod().getDeclaringClass(); + 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 d7933fae1b6..5a552ea7fa6 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 @@ -159,11 +159,9 @@ class DefaultDatabaseClient implements DatabaseClient { /** * Release the {@link Connection}. * @param connection to close. - * @return a {@link Publisher} that completes successfully when the connection is - * closed + * @return a {@link Publisher} that completes successfully when the connection is closed */ private Publisher closeConnection(Connection connection) { - return ConnectionFactoryUtils.currentConnectionFactory( obtainConnectionFactory()).then().onErrorResume(Exception.class, e -> Mono.from(connection.close())); @@ -189,24 +187,22 @@ 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) .collect(Collectors.summingInt(Integer::intValue)); } /** - * Determine SQL from potential provider object. - * @param sqlProvider object that's potentially a SqlProvider + * Get SQL from a potential provider object. + * @param object an object that is potentially an SqlProvider * @return the SQL string, or {@code null} * @see SqlProvider */ @Nullable - private static String getSql(Object sqlProvider) { - - if (sqlProvider instanceof SqlProvider) { - return ((SqlProvider) sqlProvider).getSql(); + private static String getSql(Object object) { + if (object instanceof SqlProvider) { + return ((SqlProvider) object).getSql(); } else { return null; @@ -215,7 +211,7 @@ class DefaultDatabaseClient implements DatabaseClient { /** - * Base class for {@link DatabaseClient.GenericExecuteSpec} implementations. + * Default {@link DatabaseClient.GenericExecuteSpec} implementation. */ class DefaultGenericExecuteSpec implements GenericExecuteSpec { @@ -505,12 +501,11 @@ class DefaultDatabaseClient implements DatabaseClient { private static final long serialVersionUID = -8994138383301201380L; - final Connection connection; + final transient Connection connection; - final Function> closeFunction; + final transient Function> closeFunction; - ConnectionCloseHolder(Connection connection, - Function> closeFunction) { + ConnectionCloseHolder(Connection connection, Function> closeFunction) { this.connection = connection; this.closeFunction = closeFunction; } 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 f9412f4f78b..c3c75c26d14 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 @@ -96,8 +96,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 603f23940f5..bc30ed990c4 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 @@ -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. @@ -279,6 +279,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);