This is an automated email from the ASF dual-hosted git repository. michaelo pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 322a9ab Log warning if a listener is incorrectly placed 322a9ab is described below commit 322a9aba6f891f0e11e2aea8fb99894b595e07a0 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/mbeans/LocalStrings.properties | 2 ++ java/org/apache/catalina/security/LocalStrings.properties | 2 ++ java/org/apache/catalina/security/SecurityListener.java | 4 ++++ java/org/apache/catalina/startup/LocalStrings.properties | 1 + java/org/apache/catalina/startup/VersionLoggerListener.java | 4 ++++ java/org/apache/catalina/storeconfig/LocalStrings.properties | 2 +- .../apache/catalina/storeconfig/StoreConfigLifecycleListener.java | 8 +++++--- webapps/docs/changelog.xml | 8 ++++++++ 12 files changed, 41 insertions(+), 4 deletions(-) diff --git a/java/org/apache/catalina/core/AprLifecycleListener.java b/java/org/apache/catalina/core/AprLifecycleListener.java index d92ac14..285abf9 100644 --- a/java/org/apache/catalina/core/AprLifecycleListener.java +++ b/java/org/apache/catalina/core/AprLifecycleListener.java @@ -121,6 +121,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 47c5624..4206ff7 100644 --- a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java +++ b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java @@ -107,6 +107,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 345d197..80dbc79 100644 --- a/java/org/apache/catalina/core/LocalStrings.properties +++ b/java/org/apache/catalina/core/LocalStrings.properties @@ -142,6 +142,8 @@ jniLifecycleListener.missingPathOrName=One of libraryName or libraryPath must be jreLeakListener.classToInitializeFail=Failed to load class [{0}] during Tomcat start to prevent possible memory leaks. +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 d6d7506..4f2f2dc 100644 --- a/java/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java +++ b/java/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java @@ -74,6 +74,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(sm.getString("listener.notServer", + event.getLifecycle().getClass().getSimpleName())); + } component = event.getLifecycle(); createMBeans(); } else if (Lifecycle.STOP_EVENT.equals(event.getType())) { diff --git a/java/org/apache/catalina/mbeans/LocalStrings.properties b/java/org/apache/catalina/mbeans/LocalStrings.properties index 7c4343d..70a62b9 100644 --- a/java/org/apache/catalina/mbeans/LocalStrings.properties +++ b/java/org/apache/catalina/mbeans/LocalStrings.properties @@ -23,6 +23,8 @@ globalResources.createError.userDatabase.user=Cannot create User MBean for user globalResources.noNamingContext=No global naming context defined for server globalResources.userDatabaseCreateError=Exception creating UserDatabase MBeans for [{0}] +listener.notServer=This listener must only be nested within Server elements, but is in [{0}]. + mBean.attributeNotFound=Cannot find attribute [{0}] mBean.nullAttribute=Attribute is null mBean.nullName=Attribute name is null 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 b8d0aff..facc17c 100644 --- a/java/org/apache/catalina/startup/LocalStrings.properties +++ b/java/org/apache/catalina/startup/LocalStrings.properties @@ -146,6 +146,7 @@ hostConfig.undeploy=Undeploying context [{0}] hostConfig.undeployVersion=Undeploying old version of context [{0}] which has no active session listener.createFailed=Optional listener [{0}] is not enabled +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 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/LocalStrings.properties b/java/org/apache/catalina/storeconfig/LocalStrings.properties index fdf160c..4067b86 100644 --- a/java/org/apache/catalina/storeconfig/LocalStrings.properties +++ b/java/org/apache/catalina/storeconfig/LocalStrings.properties @@ -34,7 +34,7 @@ standardContextSF.storeContext=Store context [{0}] configuration separately at p standardContextSF.storeContextWithBackup=Store context [{0}] configuration separately with backup at path [{1}] storeConfigListener.loadError=Error loading StoreConfig -storeConfigListener.notServer=The listener was added to component other than the Server and will therefore be ignored +storeConfigListener.notServer=This listener must only be nested within Server elements, but is in [{0}], ignoring it. storeConfigListener.registerError=Error registering StoreConfig MBean storeFactory.noDescriptor=Descriptor for element [{0}].[{1}] not configured diff --git a/java/org/apache/catalina/storeconfig/StoreConfigLifecycleListener.java b/java/org/apache/catalina/storeconfig/StoreConfigLifecycleListener.java index a3c7e6d..a55c8c9 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(sm.getString("storeConfigListener.notServer", + 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 5576ac4..fa65b2a 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -105,6 +105,14 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 10.1.0-M8 (markt)" rtext="in development"> + <subsection name="Catalina"> + <changelog> + <update> + Log warning if a listener is not nested inside a Server element + although it must have been. (michaelo) + </update> + </changelog> + </subsection> </section> <section name="Tomcat 10.1.0-M7 (markt)" rtext="release in progress"> <subsection name="Catalina"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org