This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new e52771c4e9 Review "Throw InstanceNotFoundException from the no-JMX
MBean server"
e52771c4e9 is described below
commit e52771c4e91fe6b76f02b482ba9f6268dcae295e
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Nov 3 17:25:13 2026 +0000
Review "Throw InstanceNotFoundException from the no-JMX MBean server"
Null oname should return the server's class loader
---
.../apache/tomcat/util/modeler/NoDescriptorRegistry.java | 6 +++++-
.../tomcat/util/modeler/TestNoDescriptorRegistry.java | 14 ++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/tomcat/util/modeler/NoDescriptorRegistry.java
b/java/org/apache/tomcat/util/modeler/NoDescriptorRegistry.java
index e95dc7a23a..350e26cd60 100644
--- a/java/org/apache/tomcat/util/modeler/NoDescriptorRegistry.java
+++ b/java/org/apache/tomcat/util/modeler/NoDescriptorRegistry.java
@@ -397,6 +397,10 @@ public class NoDescriptorRegistry extends Registry {
@Override
public ClassLoader getClassLoader(ObjectName loaderName) throws
InstanceNotFoundException {
+ if (loaderName == null) {
+ // A null name selects this server's class loader without
looking up an MBean.
+ return getClass().getClassLoader();
+ }
throw notFound(loaderName);
}
@@ -412,4 +416,4 @@ public class NoDescriptorRegistry extends Registry {
@Serial
private static final long serialVersionUID = 1L;
}
-}
\ No newline at end of file
+}
diff --git a/test/org/apache/tomcat/util/modeler/TestNoDescriptorRegistry.java
b/test/org/apache/tomcat/util/modeler/TestNoDescriptorRegistry.java
index 5bdca9987b..9ccb4d843a 100644
--- a/test/org/apache/tomcat/util/modeler/TestNoDescriptorRegistry.java
+++ b/test/org/apache/tomcat/util/modeler/TestNoDescriptorRegistry.java
@@ -62,6 +62,20 @@ public class TestNoDescriptorRegistry {
Assert.assertThrows(InstanceNotFoundException.class, () ->
server.getObjectInstance(ONAME));
}
+ @Test
+ public void testGetClassLoaderWithNullName() throws Exception {
+ MBeanServer server = new NoDescriptorRegistry().getMBeanServer();
+ // A null name requests the server's own loader rather than a
registered MBean.
+ ClassLoader loader = server.getClassLoader(null);
+ Assert.assertSame(server.getClass(),
Class.forName(server.getClass().getName(), false, loader));
+ }
+
+ @Test
+ public void testGetClassLoaderWithObjectNameThrows() throws Exception {
+ MBeanServer server = new NoDescriptorRegistry().getMBeanServer();
+ Assert.assertThrows(InstanceNotFoundException.class, () ->
server.getClassLoader(ONAME));
+ }
+
@Test
public void testRegistryGetMethodInfoThrows() throws Exception {
Registry registry = new NoDescriptorRegistry();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]