This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push: new c575781 Make clean-up fix compatible with Java 6 c575781 is described below commit c575781797adffbd82f261c250cf0e22834361f5 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Apr 18 23:25:37 2019 +0100 Make clean-up fix compatible with Java 6 --- java/org/apache/naming/factory/LookupFactory.java | 27 +++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/java/org/apache/naming/factory/LookupFactory.java b/java/org/apache/naming/factory/LookupFactory.java index ca5444b..0a5e7b4 100644 --- a/java/org/apache/naming/factory/LookupFactory.java +++ b/java/org/apache/naming/factory/LookupFactory.java @@ -16,6 +16,7 @@ */ package org.apache.naming.factory; +import java.lang.reflect.Method; import java.util.HashSet; import java.util.Hashtable; import java.util.Set; @@ -135,9 +136,10 @@ public class LookupFactory implements ObjectFactory { NamingException ne = new NamingException(msg); log.warn(msg, ne); // Close the resource we no longer need if we know how to do so - if (result instanceof AutoCloseable) { + if (isInstance(result.getClass(), "java.lang.AutoCloseable")) { try { - ((AutoCloseable) result).close(); + Method m = result.getClass().getMethod("close"); + m.invoke(result); } catch (Exception e) { // Ignore } @@ -152,4 +154,25 @@ public class LookupFactory implements ObjectFactory { return result; } + + + private static boolean isInstance(Class<?> clazz, String type) { + if (type.equals(clazz.getName())) { + return true; + } + + Class<?>[] ifaces = clazz.getInterfaces(); + for (Class<?> iface : ifaces) { + if (isInstance(iface, type)) { + return true; + } + } + + Class<?> superClazz = clazz.getSuperclass(); + if (superClazz == null) { + return false; + } else { + return isInstance(superClazz, type); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org