From b23cc01cb7981bdaf7274483a69673c519123444 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 7 Apr 2023 18:48:52 +0200 Subject: [PATCH] Revise "Ignore nonexistent default-destroy-method in XML config" This commit revises the fix in c811428512ffd04d41e558dbbc672382079ced2c. Closes gh-30301 --- .../beans/factory/support/DisposableBeanAdapter.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 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 fd5459b80e..c13d5c9600 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 @@ -115,7 +115,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { (bean instanceof AutoCloseable && CLOSE_METHOD_NAME.equals(destroyMethodNames[0])); if (!this.invokeAutoCloseable) { this.destroyMethodNames = destroyMethodNames; - Method[] destroyMethods = new Method[destroyMethodNames.length]; + List destroyMethods = new ArrayList<>(destroyMethodNames.length); for (int i = 0; i < destroyMethodNames.length; i++) { String destroyMethodName = destroyMethodNames[i]; Method destroyMethod = determineDestroyMethod(destroyMethodName); @@ -138,10 +138,10 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { } } destroyMethod = ClassUtils.getInterfaceMethodIfPossible(destroyMethod, bean.getClass()); + destroyMethods.add(destroyMethod); } - destroyMethods[i] = destroyMethod; } - this.destroyMethods = destroyMethods; + this.destroyMethods = destroyMethods.toArray(Method[]::new); } } @@ -236,9 +236,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { } else if (this.destroyMethods != null) { for (Method destroyMethod : this.destroyMethods) { - if (destroyMethod != null) { - invokeCustomDestroyMethod(destroyMethod); - } + invokeCustomDestroyMethod(destroyMethod); } } else if (this.destroyMethodNames != null) {