This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit ae194dac2f6d4f060287f2b36df80e4cce4268fd Author: opencode <[email protected]> AuthorDate: Wed Oct 7 12:36:22 2026 +0200 Match the declared signature of the findErrorPage JMX operation The descriptor of StandardContext declares the findErrorPage operation with a java.lang.String parameter, but the MBean only provided overloads for an HTTP error code and a Throwable. The modeler reflects with exactly the declared parameter types, so every invocation of the operation failed with a ReflectionException, and the Throwable variant was never reachable through JMX. Implement the operation with the declared String signature, resolving the error page by the exact configured exception type name. --- java/org/apache/catalina/mbeans/ContextMBean.java | 17 +++-- .../apache/catalina/mbeans/TestContextMBean.java | 75 ++++++++++++++++++++++ 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/java/org/apache/catalina/mbeans/ContextMBean.java b/java/org/apache/catalina/mbeans/ContextMBean.java index 23c27e1437..980793ab73 100644 --- a/java/org/apache/catalina/mbeans/ContextMBean.java +++ b/java/org/apache/catalina/mbeans/ContextMBean.java @@ -102,20 +102,23 @@ public class ContextMBean extends BaseCatalinaMBean<Context> { /** * Return the error page entry for the specified Java exception type, if any; otherwise return <code>null</code>. * - * @param exceptionType Exception type to look up + * @param exceptionType Fully qualified class name of the exception type to look up * * @return a string representation of the error page * * @throws MBeanException propagated from the managed resource access */ - public String findErrorPage(Throwable exceptionType) throws MBeanException { - Context context = doGetManagedResource(); - ErrorPage errorPage = context.findErrorPage(exceptionType); - if (errorPage != null) { - return errorPage.toString(); - } else { + public String findErrorPage(String exceptionType) throws MBeanException { + if (exceptionType == null) { return null; } + Context context = doGetManagedResource(); + for (ErrorPage errorPage : context.findErrorPages()) { + if (exceptionType.equals(errorPage.getExceptionType())) { + return errorPage.toString(); + } + } + return null; } diff --git a/test/org/apache/catalina/mbeans/TestContextMBean.java b/test/org/apache/catalina/mbeans/TestContextMBean.java new file mode 100644 index 0000000000..cbe3005e1e --- /dev/null +++ b/test/org/apache/catalina/mbeans/TestContextMBean.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.mbeans; + +import java.io.File; +import java.util.Set; + +import javax.management.MBeanServer; +import javax.management.ObjectInstance; +import javax.management.ObjectName; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.Context; +import org.apache.catalina.core.StandardContext; +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.util.descriptor.web.ErrorPage; +import org.apache.tomcat.util.modeler.Registry; + +public class TestContextMBean extends TomcatBaseTest { + + @Test + public void testFindErrorPageByExceptionType() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File(getTemporaryDirectory(), "ctxmbean"); + Assert.assertTrue(appDir.mkdirs()); + Context context = tomcat.addContext("", appDir.getAbsolutePath()); + + ErrorPage errorPage = new ErrorPage(); + errorPage.setExceptionType("java.lang.RuntimeException"); + errorPage.setLocation("/error"); + ((StandardContext) context).addErrorPage(errorPage); + + tomcat.start(); + + MBeanServer server = Registry.getRegistry(null).getMBeanServer(); + + Set<ObjectInstance> objectInstances = + server.queryMBeans(new ObjectName("*:j2eeType=WebModule,*"), null); + ObjectName oname = null; + for (ObjectInstance objectInstance : objectInstances) { + if ("//localhost/".equals(objectInstance.getObjectName().getKeyProperty("name"))) { + oname = objectInstance.getObjectName(); + } + } + Assert.assertNotNull(oname); + + Object result = server.invoke(oname, "findErrorPage", new Object[] { "java.lang.RuntimeException" }, + new String[] { "java.lang.String" }); + + Assert.assertNotNull(result); + Assert.assertTrue(result.toString(), result.toString().contains("/error")); + + // Exception types are matched by exact name, not by assignability + Assert.assertNull(server.invoke(oname, "findErrorPage", new Object[] { "java.lang.Error" }, + new String[] { "java.lang.String" })); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
