This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit fdca82b2aac91677bb467465026fdc1fb9fcc1c8
Author: opencode <[email protected]>
AuthorDate: Sun Oct 11 10:25:27 2026 +0200

    Add the null guards of getRegistry to removeRegistry
    
    removeRegistry() called getName() on the channel it was handed and
    looked the name up in a concurrent hash map, so a null channel or a
    channel without a name threw a NullPointerException instead of doing
    nothing. getRegistry() explicitly rejects both cases and the public
    static API of the registry degrades gracefully to a no-op when JMX is
    not configured, so removal should not be stricter than lookup.
    
    Both cases now return early, documented on the method, and a test
    covers the null channel as well as the missing name.
---
 java/org/apache/catalina/tribes/jmx/JmxRegistry.java     |  6 +++++-
 test/org/apache/catalina/tribes/jmx/TestJmxRegistry.java | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/tribes/jmx/JmxRegistry.java 
b/java/org/apache/catalina/tribes/jmx/JmxRegistry.java
index 1803072961..37ac357824 100644
--- a/java/org/apache/catalina/tribes/jmx/JmxRegistry.java
+++ b/java/org/apache/catalina/tribes/jmx/JmxRegistry.java
@@ -88,12 +88,16 @@ public class JmxRegistry {
     }
 
     /**
-     * Remove the JMX registry for the given channel.
+     * Remove the JMX registry for the given channel. Does nothing if the 
channel or its name is
+     * {@code null}.
      *
      * @param channel the channel
      * @param clear whether to clear the MBeans
      */
     public static void removeRegistry(Channel channel, boolean clear) {
+        if (channel == null || channel.getName() == null) {
+            return;
+        }
         JmxRegistry registry = registryCache.get(channel.getName());
         if (registry == null) {
             return;
diff --git a/test/org/apache/catalina/tribes/jmx/TestJmxRegistry.java 
b/test/org/apache/catalina/tribes/jmx/TestJmxRegistry.java
index fa44f85e45..bc61f8a0b5 100644
--- a/test/org/apache/catalina/tribes/jmx/TestJmxRegistry.java
+++ b/test/org/apache/catalina/tribes/jmx/TestJmxRegistry.java
@@ -100,4 +100,18 @@ public class TestJmxRegistry {
             JmxRegistry.removeRegistry(channel, true);
         }
     }
+
+    /*
+     * Removing the registry of a channel that never had one, or that cannot 
have one, must degrade
+     * to a no-op, as getRegistry does, rather than throw.
+     */
+    @Test
+    public void testRemoveRegistryNullGuards() throws Exception {
+        JmxRegistry.removeRegistry(null, false);
+        JmxRegistry.removeRegistry(null, true);
+
+        GroupChannel channel = new GroupChannel();
+        JmxRegistry.removeRegistry(channel, false);
+        JmxRegistry.removeRegistry(channel, true);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to