This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new e5d25a5f5f Review "Throw InstanceNotFoundException from the no-JMX
MBean server"
e5d25a5f5f is described below
commit e5d25a5f5f8d0241d873e136d1ecc467bdc7c94d
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 ed6e03efc4..c70099700c 100644
--- a/java/org/apache/tomcat/util/modeler/NoDescriptorRegistry.java
+++ b/java/org/apache/tomcat/util/modeler/NoDescriptorRegistry.java
@@ -396,6 +396,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);
}
@@ -410,4 +414,4 @@ public class NoDescriptorRegistry extends Registry {
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]