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,12 +221,15 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
((AutoCloseable) this.bean).close();
}
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);
}
}
}
}
@ -286,18 +289,23 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
destroyMethod.invoke(this.bean, args);
}
catch (InvocationTargetException ex) {
String msg = "Custom destroy method '" + destroyMethod.getName() + "' 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 '" + destroyMethod.getName() + "' 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) {
logger.warn("Failed to invoke custom destroy method '" + destroyMethod.getName() +
"' on bean with name '" + this.beanName + "'", ex);
if (logger.isWarnEnabled()) {
logger.warn("Failed to invoke custom destroy method '" + destroyMethod.getName() +
"' on bean with name '" + this.beanName + "'", ex);
}
}
}
@ -328,8 +336,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
* @param beanDefinition the corresponding bean definition
*/
public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefinition) {
return (bean instanceof DisposableBean
|| inferDestroyMethodsIfNecessary(bean.getClass(), beanDefinition) != null);
return (bean instanceof DisposableBean ||
inferDestroyMethodsIfNecessary(bean.getClass(), beanDefinition) != null);
}

View File

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