Skip to content

Commit b23cc01

Browse files
committed
Revise "Ignore nonexistent default-destroy-method in XML config"
This commit revises the fix in c811428. Closes gh-30301
1 parent 01f9788 commit b23cc01

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition be
115115
(bean instanceof AutoCloseable && CLOSE_METHOD_NAME.equals(destroyMethodNames[0]));
116116
if (!this.invokeAutoCloseable) {
117117
this.destroyMethodNames = destroyMethodNames;
118-
Method[] destroyMethods = new Method[destroyMethodNames.length];
118+
List<Method> destroyMethods = new ArrayList<>(destroyMethodNames.length);
119119
for (int i = 0; i < destroyMethodNames.length; i++) {
120120
String destroyMethodName = destroyMethodNames[i];
121121
Method destroyMethod = determineDestroyMethod(destroyMethodName);
@@ -138,10 +138,10 @@ else if (paramTypes.length == 1 && boolean.class != paramTypes[0]) {
138138
}
139139
}
140140
destroyMethod = ClassUtils.getInterfaceMethodIfPossible(destroyMethod, bean.getClass());
141+
destroyMethods.add(destroyMethod);
141142
}
142-
destroyMethods[i] = destroyMethod;
143143
}
144-
this.destroyMethods = destroyMethods;
144+
this.destroyMethods = destroyMethods.toArray(Method[]::new);
145145
}
146146
}
147147

@@ -236,9 +236,7 @@ public void destroy() {
236236
}
237237
else if (this.destroyMethods != null) {
238238
for (Method destroyMethod : this.destroyMethods) {
239-
if (destroyMethod != null) {
240-
invokeCustomDestroyMethod(destroyMethod);
241-
}
239+
invokeCustomDestroyMethod(destroyMethod);
242240
}
243241
}
244242
else if (this.destroyMethodNames != null) {

0 commit comments

Comments
 (0)