Polishing

This commit is contained in:
Juergen Hoeller 2023-01-31 18:15:28 +01:00
parent c0c9ba5c2c
commit 16937c7ce5
2 changed files with 28 additions and 21 deletions

View File

@ -221,8 +221,10 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
((AutoCloseable) this.bean).close(); ((AutoCloseable) this.bean).close();
} }
catch (Throwable ex) { catch (Throwable ex) {
if (logger.isWarnEnabled()) {
String msg = "Invocation of close method failed on bean with name '" + this.beanName + "'"; String msg = "Invocation of close method failed on bean with name '" + this.beanName + "'";
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
// Log at warn level like below but add the exception stacktrace only with debug level
logger.warn(msg, ex); logger.warn(msg, ex);
} }
else { else {
@ -230,6 +232,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
} }
} }
} }
}
else if (this.destroyMethods != null) { else if (this.destroyMethods != null) {
for (Method destroyMethod : this.destroyMethods) { for (Method destroyMethod : this.destroyMethods) {
invokeCustomDestroyMethod(destroyMethod); invokeCustomDestroyMethod(destroyMethod);
@ -286,20 +289,25 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
destroyMethod.invoke(this.bean, args); destroyMethod.invoke(this.bean, args);
} }
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {
if (logger.isWarnEnabled()) {
String msg = "Custom destroy method '" + destroyMethod.getName() + "' on bean with name '" + String msg = "Custom destroy method '" + destroyMethod.getName() + "' on bean with name '" +
this.beanName + "' threw an exception"; this.beanName + "' threw an exception";
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
// Log at warn level like below but add the exception stacktrace only with debug level
logger.warn(msg, ex.getTargetException()); logger.warn(msg, ex.getTargetException());
} }
else { else {
logger.warn(msg + ": " + ex.getTargetException()); logger.warn(msg + ": " + ex.getTargetException());
} }
} }
}
catch (Throwable ex) { catch (Throwable ex) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to invoke custom destroy method '" + destroyMethod.getName() + logger.warn("Failed to invoke custom destroy method '" + destroyMethod.getName() +
"' on bean with name '" + this.beanName + "'", ex); "' on bean with name '" + this.beanName + "'", ex);
} }
} }
}
/** /**
@ -328,8 +336,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
* @param beanDefinition the corresponding bean definition * @param beanDefinition the corresponding bean definition
*/ */
public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefinition) { public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefinition) {
return (bean instanceof DisposableBean return (bean instanceof DisposableBean ||
|| inferDestroyMethodsIfNecessary(bean.getClass(), beanDefinition) != null); inferDestroyMethodsIfNecessary(bean.getClass(), beanDefinition) != null);
} }

View File

@ -244,8 +244,8 @@ class DefaultDatabaseClient implements DatabaseClient {
this.filterFunction = filterFunction; this.filterFunction = filterFunction;
} }
@Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override
public DefaultGenericExecuteSpec bind(int index, Object value) { public DefaultGenericExecuteSpec bind(int index, Object value) {
assertNotPreparedOperation(); assertNotPreparedOperation();
Assert.notNull(value, () -> String.format( Assert.notNull(value, () -> String.format(
@ -275,8 +275,8 @@ class DefaultDatabaseClient implements DatabaseClient {
return new DefaultGenericExecuteSpec(byIndex, this.byName, this.sqlSupplier, this.filterFunction); return new DefaultGenericExecuteSpec(byIndex, this.byName, this.sqlSupplier, this.filterFunction);
} }
@Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override
public DefaultGenericExecuteSpec bind(String name, Object value) { public DefaultGenericExecuteSpec bind(String name, Object value) {
assertNotPreparedOperation(); assertNotPreparedOperation();
@ -522,8 +522,7 @@ class DefaultDatabaseClient implements DatabaseClient {
final transient Function<Connection, Publisher<Void>> closeFunction; final transient Function<Connection, Publisher<Void>> closeFunction;
ConnectionCloseHolder(Connection connection, ConnectionCloseHolder(Connection connection, Function<Connection, Publisher<Void>> closeFunction) {
Function<Connection, Publisher<Void>> closeFunction) {
this.connection = connection; this.connection = connection;
this.closeFunction = closeFunction; this.closeFunction = closeFunction;
} }