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

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


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

commit 6f4f0973c130f696347a2265dce6f44fd60e39b7
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 41054cbb13..4dcf823923 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
@@ -635,8 +638,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();
@@ -869,7 +871,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