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

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


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 9db637f84a Fix possible NPE
9db637f84a is described below

commit 9db637f84a8a0023827c78a9c317322318cc051d
Author: remm <r...@apache.org>
AuthorDate: Fri Sep 8 15:40:52 2023 +0200

    Fix possible NPE
    
    Also cleanup exceptions and error message.
    Found by coverity.
---
 java/org/apache/catalina/mbeans/LocalStrings.properties | 1 +
 java/org/apache/catalina/mbeans/MBeanFactory.java       | 8 +++++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/catalina/mbeans/LocalStrings.properties 
b/java/org/apache/catalina/mbeans/LocalStrings.properties
index 70a62b95fe..2d996c6f2c 100644
--- a/java/org/apache/catalina/mbeans/LocalStrings.properties
+++ b/java/org/apache/catalina/mbeans/LocalStrings.properties
@@ -36,6 +36,7 @@ mBeanFactory.contextDestroyError=Error during context [{0}] 
destroy
 mBeanFactory.contextRemove.addServicedFail=Unable to remove context [{0}] as 
another component is currently servicing that context
 mBeanFactory.managerContext=Manager components may only be added to Contexts.
 mBeanFactory.noDeployer=Deployer not found for host [{0}]
+mBeanFactory.noParent=No parent found with object name [{0}]
 mBeanFactory.noService=Service with the domain [{0}] was not found
 mBeanFactory.notServer=The container is not a Server
 
diff --git a/java/org/apache/catalina/mbeans/MBeanFactory.java 
b/java/org/apache/catalina/mbeans/MBeanFactory.java
index 4ece19c135..1ddbcbb5be 100644
--- a/java/org/apache/catalina/mbeans/MBeanFactory.java
+++ b/java/org/apache/catalina/mbeans/MBeanFactory.java
@@ -238,6 +238,9 @@ public class MBeanFactory {
     private String addRealmToParent(String parent, Realm realm) throws 
Exception {
         ObjectName pname = new ObjectName(parent);
         Container container = getParentContainerFromParent(pname);
+        if (container == null) {
+            throw new 
IllegalArgumentException(sm.getString("mBeanFactory.noParent", parent));
+        }
         // Add the new instance to its parent component
         container.setRealm(realm);
         // Return the corresponding MBean name
@@ -603,8 +606,7 @@ public class MBeanFactory {
         Container container = getParentContainerFromParent(parentName);
 
         if (container == null) {
-            // TODO
-            throw new IllegalArgumentException();
+            throw new 
IllegalArgumentException(sm.getString("mBeanFactory.noParent", parent));
         }
 
         Valve valve = (Valve) 
Class.forName(className).getConstructor().newInstance();
@@ -837,7 +839,7 @@ public class MBeanFactory {
     public void removeService(String name) throws Exception {
 
         if (!(container instanceof Server)) {
-            throw new Exception();
+            throw new Exception(sm.getString("mBeanFactory.notServer"));
         }
 
         // Acquire a reference to the component to be removed


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to