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

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

commit 25b13e19afb78abbb6b62180dc111e41b12a168a
Author: opencode <[email protected]>
AuthorDate: Wed Oct 7 13:42:44 2026 +0200

    Report when a naming entry was not actually added through JMX
    
    NamingResourcesImpl uses a single set of names shared by every naming
    entry type, so adding an environment, resource or resource link through
    this MBean silently does nothing when the requested name is already
    claimed by an entry of a different type, while the add* operations still
    computed and returned the ObjectName of an MBean that was never
    registered. Re-check the entry with the corresponding find method after
    the add call and throw IllegalArgumentException when nothing was added.
    Also remove the ObjectName.unquote() calls in removeResource() and
    removeResourceLink(). JMX operation parameters arrive as plain strings,
    not as ObjectName key property values, so unquoting mangled names that
    legitimately begin or end with a quote character and allowed removal of
    an entry whose actual name differed from the one supplied.
---
 .../apache/catalina/mbeans/NamingResourcesMBean.java | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/mbeans/NamingResourcesMBean.java 
b/java/org/apache/catalina/mbeans/NamingResourcesMBean.java
index 0fcf1ca09e..2cf577b11c 100644
--- a/java/org/apache/catalina/mbeans/NamingResourcesMBean.java
+++ b/java/org/apache/catalina/mbeans/NamingResourcesMBean.java
@@ -153,6 +153,12 @@ public class NamingResourcesMBean extends BaseModelMBean {
         env.setType(type);
         env.setValue(value);
         nresources.addEnvironment(env);
+        if (nresources.findEnvironment(envName) == null) {
+            // The name is already claimed by another entry type and the entry
+            // was not added
+            throw new IllegalArgumentException(
+                    
sm.getString("namingResourcesMBean.addAlreadyExists.environment", envName));
+        }
 
         // Return the corresponding MBean name
         ManagedBean managed = registry.findManagedBean("ContextEnvironment");
@@ -186,6 +192,12 @@ public class NamingResourcesMBean extends BaseModelMBean {
         resource.setName(resourceName);
         resource.setType(type);
         nresources.addResource(resource);
+        if (nresources.findResource(resourceName) == null) {
+            // The name is already claimed by another entry type and the entry
+            // was not added
+            throw new IllegalArgumentException(
+                    
sm.getString("namingResourcesMBean.addAlreadyExists.resource", resourceName));
+        }
 
         // Return the corresponding MBean name
         ManagedBean managed = registry.findManagedBean("ContextResource");
@@ -219,6 +231,12 @@ public class NamingResourcesMBean extends BaseModelMBean {
         resourceLink.setName(resourceLinkName);
         resourceLink.setType(type);
         nresources.addResourceLink(resourceLink);
+        if (nresources.findResourceLink(resourceLinkName) == null) {
+            // The name is already claimed by another entry type and the entry
+            // was not added
+            throw new IllegalArgumentException(
+                    
sm.getString("namingResourcesMBean.addAlreadyExists.resourceLink", 
resourceLinkName));
+        }
 
         // Return the corresponding MBean name
         ManagedBean managed = registry.findManagedBean("ContextResourceLink");
@@ -252,7 +270,6 @@ public class NamingResourcesMBean extends BaseModelMBean {
      * @param resourceName Name of the resource reference to remove
      */
     public void removeResource(String resourceName) {
-        resourceName = ObjectName.unquote(resourceName);
         NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
         if (nresources == null) {
             return;
@@ -272,7 +289,6 @@ public class NamingResourcesMBean extends BaseModelMBean {
      * @param resourceLinkName Name of the resource link reference to remove
      */
     public void removeResourceLink(String resourceLinkName) {
-        resourceLinkName = ObjectName.unquote(resourceLinkName);
         NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
         if (nresources == null) {
             return;


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

Reply via email to