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 a972c038e24f9d749cce3401c2deed87c3c24d18 Author: remm <[email protected]> AuthorDate: Wed Oct 7 14:40:57 2026 +0200 Revert "Match the declared signature of the findErrorPage JMX operation" This reverts commit 689ffc8f24c37bdc1099696333c8bbd6d1981e0a. --- java/org/apache/catalina/mbeans/ContextMBean.java | 17 ++--- .../apache/catalina/mbeans/TestContextMBean.java | 75 ---------------------- 2 files changed, 7 insertions(+), 85 deletions(-) diff --git a/java/org/apache/catalina/mbeans/ContextMBean.java b/java/org/apache/catalina/mbeans/ContextMBean.java index 980793ab73..23c27e1437 100644 --- a/java/org/apache/catalina/mbeans/ContextMBean.java +++ b/java/org/apache/catalina/mbeans/ContextMBean.java @@ -102,23 +102,20 @@ 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 Fully qualified class name of the exception type to look up + * @param exceptionType Exception type to look up * * @return a string representation of the error page * * @throws MBeanException propagated from the managed resource access */ - public String findErrorPage(String exceptionType) throws MBeanException { - if (exceptionType == null) { - return null; - } + public String findErrorPage(Throwable exceptionType) throws MBeanException { Context context = doGetManagedResource(); - for (ErrorPage errorPage : context.findErrorPages()) { - if (exceptionType.equals(errorPage.getExceptionType())) { - return errorPage.toString(); - } + ErrorPage errorPage = context.findErrorPage(exceptionType); + if (errorPage != null) { + return errorPage.toString(); + } else { + return null; } - return null; } diff --git a/test/org/apache/catalina/mbeans/TestContextMBean.java b/test/org/apache/catalina/mbeans/TestContextMBean.java deleted file mode 100644 index cbe3005e1e..0000000000 --- a/test/org/apache/catalina/mbeans/TestContextMBean.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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]
