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

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


The following commit(s) were added to refs/heads/8.5.x by this push:
     new 30e532f  Do not throw NPE when MBean operation cannot be found.
30e532f is described below

commit 30e532f4f050c33ad892ff595e73efa55f0dacb7
Author: Christopher Schultz <ch...@christopherschultz.net>
AuthorDate: Wed Jan 8 08:48:41 2020 -0500

    Do not throw NPE when MBean operation cannot be found.
---
 java/org/apache/catalina/manager/JMXProxyServlet.java    | 16 ++++++++++++++++
 java/org/apache/catalina/manager/LocalStrings.properties |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/java/org/apache/catalina/manager/JMXProxyServlet.java 
b/java/org/apache/catalina/manager/JMXProxyServlet.java
index 762e64a..2e98e19 100644
--- a/java/org/apache/catalina/manager/JMXProxyServlet.java
+++ b/java/org/apache/catalina/manager/JMXProxyServlet.java
@@ -22,6 +22,7 @@ import java.util.Set;
 
 import javax.management.Attribute;
 import javax.management.MBeanException;
+import javax.management.MBeanInfo;
 import javax.management.MBeanOperationInfo;
 import javax.management.MBeanParameterInfo;
 import javax.management.MBeanServer;
@@ -35,6 +36,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.catalina.mbeans.MBeanDumper;
+import org.apache.catalina.tribes.util.StringManager;
 import org.apache.tomcat.util.modeler.Registry;
 
 /**
@@ -51,6 +53,8 @@ public class JMXProxyServlet extends HttpServlet {
     // without any parameters.
     private static final String[] NO_PARAMETERS = new String[0];
 
+    private static final StringManager sm = 
StringManager.getManager(JMXProxyServlet.class);
+
     // ----------------------------------------------------- Instance Variables
     /**
      * MBean server.
@@ -261,6 +265,18 @@ public class JMXProxyServlet extends HttpServlet {
             throws OperationsException, MBeanException, ReflectionException {
         ObjectName oname = new ObjectName(onameStr);
         MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, 
operation);
+        if(null == methodInfo) {
+            // getMethodInfo returns null for both "object not found" and 
"operation not found"
+            MBeanInfo info = null;
+            try {
+                info = registry.getMBeanServer().getMBeanInfo(oname);
+
+                throw new 
IllegalArgumentException(sm.getString("jmxProxyServlet.noOperationOnBean", 
operation, onameStr, info.getClassName()));
+            } catch (Exception e) {
+                throw new 
IllegalArgumentException(sm.getString("jmxProxyServlet.noBeanFound", onameStr));
+            }
+        }
+
         MBeanParameterInfo[] signature = methodInfo.getSignature();
         String[] signatureTypes = new String[signature.length];
         Object[] values = new Object[signature.length];
diff --git a/java/org/apache/catalina/manager/LocalStrings.properties 
b/java/org/apache/catalina/manager/LocalStrings.properties
index 556e0c1..bde5084 100644
--- a/java/org/apache/catalina/manager/LocalStrings.properties
+++ b/java/org/apache/catalina/manager/LocalStrings.properties
@@ -177,3 +177,6 @@ managerServlet.vminfo=OK - VM info
 
 statusServlet.complete=Complete Server Status
 statusServlet.title=Server Status
+
+jmxProxyServlet.noOperationOnBean=Cannot find operation [{0}] on object name 
[{1}], which is a [{2}]
+jmxProxyServlet.noBeanFound=Cannot find MBean with object name [{0}]


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

Reply via email to