From: markt Date: Sun, 21 Mar 2010 22:18:03 +0000 (+0000) Subject: Always use the InstanceManager to create listeners, filters & servlets X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=99a14c6594a8a231e6c07a201ff5a7582d78adce;p=tomcat7.0 Always use the InstanceManager to create listeners, filters & servlets git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@925921 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/ApplicationContext.java b/java/org/apache/catalina/core/ApplicationContext.java index 5d1098908..2fbc24968 100644 --- a/java/org/apache/catalina/core/ApplicationContext.java +++ b/java/org/apache/catalina/core/ApplicationContext.java @@ -1207,27 +1207,36 @@ public class ApplicationContext @Override public void addListener(String className) { - Class clazz; - try { - clazz = Class.forName(className); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException(sm.getString( - "applicationContext.addListener.iae.cnfe", className), e); - } - - if (!EventListener.class.isAssignableFrom(clazz)) { - throw new IllegalArgumentException(sm.getString( - "applicationContext.addListener.iae.wrongType", className)); - } + Object obj = context.getInstanceManager().newInstance(className); - try { - @SuppressWarnings("unchecked") // tested above - EventListener listener = createListener((Class)clazz); + if (!(obj instanceof EventListener)) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.wrongType", + className)); + } + + EventListener listener = (EventListener) obj; addListener(listener); - } catch (ServletException e) { + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.cnfe", className), + e); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.cnfe", className), + e); + } catch (NamingException e) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.cnfe", className), + e); + } catch (InstantiationException e) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.cnfe", className), + e); + } catch (ClassNotFoundException e) { throw new IllegalArgumentException(sm.getString( - "applicationContext.addListener.iae.wrongType", className), + "applicationContext.addListener.iae.cnfe", className), e); }