Skip to content

Commit 249b798

Browse files
committed
Direct reference to JDK 7 AutoCloseable interface
Issue: SPR-13188
1 parent c316088 commit 249b798

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.beans.factory.support;
1818

19-
import java.io.Closeable;
2019
import java.io.Serializable;
2120
import java.lang.reflect.InvocationTargetException;
2221
import java.lang.reflect.Method;
@@ -68,18 +67,6 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
6867

6968
private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class);
7069

71-
private static Class<?> closeableInterface;
72-
73-
static {
74-
try {
75-
closeableInterface = ClassUtils.forName("java.lang.AutoCloseable",
76-
DisposableBeanAdapter.class.getClassLoader());
77-
}
78-
catch (ClassNotFoundException ex) {
79-
closeableInterface = Closeable.class;
80-
}
81-
}
82-
8370

8471
private final Object bean;
8572

@@ -191,7 +178,7 @@ private DisposableBeanAdapter(Object bean, String beanName, boolean invokeDispos
191178
private String inferDestroyMethodIfNecessary(Object bean, RootBeanDefinition beanDefinition) {
192179
String destroyMethodName = beanDefinition.getDestroyMethodName();
193180
if (AbstractBeanDefinition.INFER_METHOD.equals(destroyMethodName) ||
194-
(destroyMethodName == null && closeableInterface.isInstance(bean))) {
181+
(destroyMethodName == null && bean instanceof AutoCloseable)) {
195182
// Only perform destroy method inference or Closeable detection
196183
// in case of the bean not explicitly implementing DisposableBean
197184
if (!(bean instanceof DisposableBean)) {
@@ -406,7 +393,7 @@ protected Object writeReplace() {
406393
* @param beanDefinition the corresponding bean definition
407394
*/
408395
public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefinition) {
409-
if (bean instanceof DisposableBean || closeableInterface.isInstance(bean)) {
396+
if (bean instanceof DisposableBean || bean instanceof AutoCloseable) {
410397
return true;
411398
}
412399
String destroyMethodName = beanDefinition.getDestroyMethodName();

0 commit comments

Comments
 (0)