This is an automated email from the ASF dual-hosted git repository. michaelo pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 4896083 Log warning if a listener is incorrectly placed 4896083 is described below commit 48960832ca7e5c6da77d2fb83548e4f92fb37040 Author: Michael Osipov <micha...@apache.org> AuthorDate: Mon Nov 8 20:39:09 2021 +0100 Log warning if a listener is incorrectly placed Some listeners are intented to be nested inside a Server element only. If a listener is misplaced a warning message is logged. --- java/org/apache/catalina/core/AprLifecycleListener.java | 4 ++++ .../org/apache/catalina/core/JreMemoryLeakPreventionListener.java | 4 ++++ java/org/apache/catalina/core/LocalStrings.properties | 2 ++ .../apache/catalina/mbeans/GlobalResourcesLifecycleListener.java | 4 ++++ java/org/apache/catalina/security/LocalStrings.properties | 2 ++ java/org/apache/catalina/security/SecurityListener.java | 4 ++++ java/org/apache/catalina/startup/LocalStrings.properties | 2 ++ java/org/apache/catalina/startup/VersionLoggerListener.java | 4 ++++ .../apache/catalina/storeconfig/StoreConfigLifecycleListener.java | 8 +++++--- webapps/docs/changelog.xml | 4 ++++ 10 files changed, 35 insertions(+), 3 deletions(-) diff --git a/java/org/apache/catalina/core/AprLifecycleListener.java b/java/org/apache/catalina/core/AprLifecycleListener.java index 3546946..80dc5a5 100644 --- a/java/org/apache/catalina/core/AprLifecycleListener.java +++ b/java/org/apache/catalina/core/AprLifecycleListener.java @@ -126,6 +126,10 @@ public class AprLifecycleListener implements LifecycleListener { if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) { synchronized (lock) { + if (!(event.getLifecycle() instanceof Server)) { + log.warn(sm.getString("listener.notServer", + event.getLifecycle().getClass().getSimpleName())); + } init(); for (String msg : initInfoLogMessages) { log.info(msg); diff --git a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java index 59e8ff7..58f1382 100644 --- a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java +++ b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java @@ -234,6 +234,10 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { public void lifecycleEvent(LifecycleEvent event) { // Initialise these classes when Tomcat starts if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) { + if (!(event.getLifecycle() instanceof Server)) { + log.warn(sm.getString("listener.notServer", + event.getLifecycle().getClass().getSimpleName())); + } /* * First call to this loads all drivers visible to the current class diff --git a/java/org/apache/catalina/core/LocalStrings.properties b/java/org/apache/catalina/core/LocalStrings.properties index 3c5b58a..1e5d56e 100644 --- a/java/org/apache/catalina/core/LocalStrings.properties +++ b/java/org/apache/catalina/core/LocalStrings.properties @@ -150,6 +150,8 @@ jreLeakListener.jarUrlConnCacheFail=Failed to disable Jar URL connection caching jreLeakListener.ldapPoolManagerFail=Failed to trigger creation of the com.sun.jndi.ldap.LdapPoolManager class during Tomcat start to prevent possible memory leaks. This is expected on non-Sun JVMs. jreLeakListener.xmlParseFail=Error whilst attempting to prevent memory leaks during XML parsing +listener.notServer=This listener must only be nested within Server elements, but is in [{0}]. + naming.addEnvEntry=Adding environment entry [{0}] naming.addResourceEnvRef=Adding resource env ref [{0}] naming.bindFailed=Failed to bind object: [{0}] diff --git a/java/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java b/java/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java index 125d044..4539b31 100644 --- a/java/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java +++ b/java/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java @@ -79,6 +79,10 @@ public class GlobalResourcesLifecycleListener implements LifecycleListener { public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.START_EVENT.equals(event.getType())) { + if (!(event.getLifecycle() instanceof Server)) { + log.warn("This listener must only be nested within Server elements, but is in [" + + event.getLifecycle().getClass().getSimpleName() + "]."); + } component = event.getLifecycle(); createMBeans(); } else if (Lifecycle.STOP_EVENT.equals(event.getType())) { diff --git a/java/org/apache/catalina/security/LocalStrings.properties b/java/org/apache/catalina/security/LocalStrings.properties index b97a018..1c604fd 100644 --- a/java/org/apache/catalina/security/LocalStrings.properties +++ b/java/org/apache/catalina/security/LocalStrings.properties @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +listener.notServer=This listener must only be nested within Server elements, but is in [{0}]. + SecurityListener.checkUmaskFail=Start attempted with umask setting of [{0}]. Running Tomcat without a umask at least as restrictive as [{1}] has been blocked by the Lifecycle listener org.apache.catalina.security.SecurityListener (usually configured in CATALINA_BASE/conf/server.xml) SecurityListener.checkUmaskNone=No umask setting was found in system property [{0}]. However, it appears Tomcat is running on a platform that supports umask. The system property is typically set in CATALINA_HOME/bin/catalina.sh. The Lifecycle listener org.apache.catalina.security.SecurityListener (usually configured in CATALINA_BASE/conf/server.xml) expects a umask at least as restrictive as [{1}] SecurityListener.checkUmaskParseFail=Failed to parse value [{0}] as a valid umask. diff --git a/java/org/apache/catalina/security/SecurityListener.java b/java/org/apache/catalina/security/SecurityListener.java index cee5ae0..6df8412 100644 --- a/java/org/apache/catalina/security/SecurityListener.java +++ b/java/org/apache/catalina/security/SecurityListener.java @@ -65,6 +65,10 @@ public class SecurityListener implements LifecycleListener { public void lifecycleEvent(LifecycleEvent event) { // This is the earliest event in Lifecycle if (event.getType().equals(Lifecycle.BEFORE_INIT_EVENT)) { + if (!(event.getLifecycle() instanceof Server)) { + log.warn(sm.getString("listener.notServer", + event.getLifecycle().getClass().getSimpleName())); + } doChecks(); } } diff --git a/java/org/apache/catalina/startup/LocalStrings.properties b/java/org/apache/catalina/startup/LocalStrings.properties index 44e48a5..bc68705 100644 --- a/java/org/apache/catalina/startup/LocalStrings.properties +++ b/java/org/apache/catalina/startup/LocalStrings.properties @@ -128,6 +128,8 @@ hostConfig.stop=HostConfig: Processing STOP hostConfig.undeploy=Undeploying context [{0}] hostConfig.undeployVersion=Undeploying old version of context [{0}] which has no active session +listener.notServer=This listener must only be nested within Server elements, but is in [{0}]. + passwdUserDatabase.readFail=Failed to obtain a complete set of users from /etc/passwd tomcat.addWebapp.conflictChild=Unable to deploy WAR at [{0}] to context path [{1}] because of existing context [{2}] diff --git a/java/org/apache/catalina/startup/VersionLoggerListener.java b/java/org/apache/catalina/startup/VersionLoggerListener.java index 6ca2ea8..472cd46 100644 --- a/java/org/apache/catalina/startup/VersionLoggerListener.java +++ b/java/org/apache/catalina/startup/VersionLoggerListener.java @@ -84,6 +84,10 @@ public class VersionLoggerListener implements LifecycleListener { @Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) { + if (!(event.getLifecycle() instanceof Server)) { + log.warn(sm.getString("listener.notServer", + event.getLifecycle().getClass().getSimpleName())); + } log(); } } diff --git a/java/org/apache/catalina/storeconfig/StoreConfigLifecycleListener.java b/java/org/apache/catalina/storeconfig/StoreConfigLifecycleListener.java index ad2da88..e34c91f 100644 --- a/java/org/apache/catalina/storeconfig/StoreConfigLifecycleListener.java +++ b/java/org/apache/catalina/storeconfig/StoreConfigLifecycleListener.java @@ -32,8 +32,9 @@ import org.apache.tomcat.util.res.StringManager; /** * Loads and registers a StoreConfig MBean with the name - * <i>Catalina:type=StoreConfig</i>. This listener should only be used with a - * {@link Server}. + * <i>Catalina:type=StoreConfig</i>. + * <p> + * This listener must only be nested within {@link Server} elements. */ public class StoreConfigLifecycleListener implements LifecycleListener { @@ -64,7 +65,8 @@ public class StoreConfigLifecycleListener implements LifecycleListener { if (event.getSource() instanceof Server) { createMBean((Server) event.getSource()); } else { - log.warn(sm.getString("storeConfigListener.notServer")); + log.warn("This listener must only be nested within Server elements, but is in [" + + event.getLifecycle().getClass().getSimpleName() + "]."); } } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) { if (oname != null) { diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 5d72085..57f8993 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -116,6 +116,10 @@ Add Javadoc comment which listeners must be nested whithin <code>Server</code> elements only. (michaelo) </docs> + <update> + Log warning if a listener is not nested inside a Server element + although it must have been. (michaelo) + </update> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org