From: kkolinko Date: Wed, 6 Oct 2010 01:03:29 +0000 (+0000) Subject: Amending the fix for X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5cd2c51342f86b8be6a7242bb1334bb65856ec25;p=tomcat7.0 Amending the fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=49669 Do not depend on the deprecated class. Use reflection instead. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1004868 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java index 9af75ca0b..19496773e 100644 --- a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java +++ b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java @@ -25,7 +25,6 @@ import java.net.URL; import java.net.URLConnection; import javax.imageio.ImageIO; -import javax.security.auth.Policy; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -233,10 +232,24 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { */ if (securityPolicyProtection) { try { - Policy.getPolicy(); + // Policy.getPolicy(); + Class policyClass = Class + .forName("javax.security.auth.Policy"); + Method method = policyClass.getMethod("getPolicy"); + method.invoke(null); + } catch(ClassNotFoundException e) { + // Ignore. The class is deprecated. } catch(SecurityException e) { // Ignore. Don't need call to getPolicy() to be successful, // just need to trigger static initializer. + } catch (NoSuchMethodException e) { + log.warn(sm.getString("jreLeakListener.authPolicyFail"), e); + } catch (IllegalArgumentException e) { + log.warn(sm.getString("jreLeakListener.authPolicyFail"), e); + } catch (IllegalAccessException e) { + log.warn(sm.getString("jreLeakListener.authPolicyFail"), e); + } catch (InvocationTargetException e) { + log.warn(sm.getString("jreLeakListener.authPolicyFail"), e); } } diff --git a/java/org/apache/catalina/core/LocalStrings.properties b/java/org/apache/catalina/core/LocalStrings.properties index 9a993b07e..45b59cea8 100644 --- a/java/org/apache/catalina/core/LocalStrings.properties +++ b/java/org/apache/catalina/core/LocalStrings.properties @@ -80,6 +80,7 @@ jreLeakListener.keepAliveFail=Failed to trigger creation of the sun.net.www.http jreLeakListener.gcDaemonFail=Failed to trigger creation of the GC Daemon thread during Tomcat start to prevent possible memory leaks. This is expected on non-Sun JVMs. jreLeakListener.jarUrlConnCacheFail=Failed to disable Jar URL connection caching by default jreLeakListener.xmlParseFail=Error whilst attempting to prevent memory leaks during XML parsing +jreLeakListener.authPolicyFail=Error whilst attempting to prevent memory leak in javax.security.auth.Policy class naming.wsdlFailed=Failed to find wsdl file: {0} naming.bindFailed=Failed to bind object: {0} naming.jmxRegistrationFailed=Failed to register in JMX: {0} diff --git a/webapps/docs/config/listeners.xml b/webapps/docs/config/listeners.xml index 289091946..713d1ffa1 100644 --- a/webapps/docs/config/listeners.xml +++ b/webapps/docs/config/listeners.xml @@ -271,8 +271,8 @@ service:jmx:rmi://<hostname>:10002/jndi/rmi://<hostname>:10001/jmxrm -

Enables protection so that usage of - javax.security.auth.Policy by a web application does not +

Enables protection so that usage of the deprecated + javax.security.auth.Policy class by a web application does not result in a memory leak. The first access of this class will trigger the static initializer that will retain a static reference to the context class loader. The protection calls the getPolicy() method