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 c25288119c684202951381c2d1af045c381480cc Author: opencode <[email protected]> AuthorDate: Thu Oct 15 12:22:57 2026 +0200 Document and clean up the descriptor load result ModelerSource.loadDescriptors() is documented to return a list of object names, but both sources provided with Tomcat registered the descriptors they loaded with the given registry and never recorded any object names, so the private fields backing the return value were dead and the returned list was always empty. No object name identifying a loaded descriptor exists in the modeler, so populating the list would have invented a semantic that no code produces. Remove the dead fields and return the immutable empty list, following the precedent already set by the no-descriptor registry, and document in ModelerSource and Registry.load() that the provided sources register their descriptors with the registry and do not return object names. Callers must not assume the returned list is mutable. --- java/org/apache/tomcat/util/modeler/Registry.java | 4 +- .../modules/MbeansDescriptorsDigesterSource.java | 4 +- .../MbeansDescriptorsIntrospectionSource.java | 4 +- .../tomcat/util/modeler/modules/ModelerSource.java | 4 +- .../TestMbeansDescriptorsDigesterSource.java | 8 ++- .../TestMbeansDescriptorsIntrospectionSource.java | 60 +++++++++++----------- 6 files changed, 47 insertions(+), 37 deletions(-) diff --git a/java/org/apache/tomcat/util/modeler/Registry.java b/java/org/apache/tomcat/util/modeler/Registry.java index 2bae09dfd6..a3bce6d157 100644 --- a/java/org/apache/tomcat/util/modeler/Registry.java +++ b/java/org/apache/tomcat/util/modeler/Registry.java @@ -575,7 +575,9 @@ public class Registry implements RegistryMBean, MBeanRegistration { * @param source The bean * @param param A type to load * - * @return List of descriptors + * @return List of object names. The sources provided with Tomcat + * register the descriptors with this registry instead of + * returning object names, so the returned list is empty. * * @throws Exception Error loading descriptors */ diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java index 9e271a7f2d..d70dcb0474 100644 --- a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java +++ b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java @@ -19,6 +19,7 @@ package org.apache.tomcat.util.modeler.modules; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.management.ObjectName; @@ -46,7 +47,6 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource { private static final Object dLock = new Object(); private Registry registry; - private final List<ObjectName> mbeans = new ArrayList<>(); private static Digester digester = null; private static Digester createDigester() { @@ -129,7 +129,7 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource { setRegistry(registry); setSource(source); execute(); - return mbeans; + return Collections.emptyList(); } /** diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java index b736e1f972..0f1974a157 100644 --- a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java +++ b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java @@ -21,6 +21,7 @@ import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -56,7 +57,6 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource { private Registry registry; private String type; - private final List<ObjectName> mbeans = new ArrayList<>(); /** * Set the registry. @@ -91,7 +91,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource { setType(type); setSource(source); execute(); - return mbeans; + return Collections.emptyList(); } /** diff --git a/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java b/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java index d4645bd95d..6b3ee0caa2 100644 --- a/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java +++ b/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java @@ -49,7 +49,9 @@ public abstract class ModelerSource { * @param type The bean registry type * @param source Introspected object or some other source * - * @return a list of object names + * @return a list of object names. The sources provided with Tomcat + * register the descriptors with the given registry instead of + * returning object names, so the returned list is empty. * * @throws Exception Error loading descriptors */ diff --git a/test/org/apache/tomcat/util/modeler/modules/TestMbeansDescriptorsDigesterSource.java b/test/org/apache/tomcat/util/modeler/modules/TestMbeansDescriptorsDigesterSource.java index c512cdf2fe..ca7a0e56d5 100644 --- a/test/org/apache/tomcat/util/modeler/modules/TestMbeansDescriptorsDigesterSource.java +++ b/test/org/apache/tomcat/util/modeler/modules/TestMbeansDescriptorsDigesterSource.java @@ -21,8 +21,11 @@ import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import javax.management.ObjectName; + import org.junit.Assert; import org.junit.Test; @@ -54,8 +57,11 @@ public class TestMbeansDescriptorsDigesterSource { AtomicBoolean closed = new AtomicBoolean(); Registry registry = Registry.getRegistry(null); - registry.load(null, createTrackingStream(XML, closed), null); + List<ObjectName> result = registry.load(null, createTrackingStream(XML, closed), null); + // Descriptors are registered with the registry, no object names are + // returned + Assert.assertTrue(result.isEmpty()); Assert.assertTrue(closed.get()); Assert.assertNotNull(registry.findManagedBean("TestDigesterSourceBean")); } diff --git a/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java b/test/org/apache/tomcat/util/modeler/modules/TestMbeansDescriptorsIntrospectionSource.java similarity index 50% copy from java/org/apache/tomcat/util/modeler/modules/ModelerSource.java copy to test/org/apache/tomcat/util/modeler/modules/TestMbeansDescriptorsIntrospectionSource.java index d4645bd95d..381457d618 100644 --- a/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java +++ b/test/org/apache/tomcat/util/modeler/modules/TestMbeansDescriptorsIntrospectionSource.java @@ -20,38 +20,38 @@ import java.util.List; import javax.management.ObjectName; +import org.junit.Assert; +import org.junit.Test; + import org.apache.tomcat.util.modeler.Registry; -import org.apache.tomcat.util.res.StringManager; -/** - * Source for descriptor data. More sources can be added. - */ -public abstract class ModelerSource { - /** - * Default constructor. - */ - public ModelerSource() { +public class TestMbeansDescriptorsIntrospectionSource { + + public static class TesterIntrospectionBean { + + private String value = "test"; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } } - /** - * The string manager for the package that contains {@link Registry}. - */ - protected static final StringManager sm = StringManager.getManager(Registry.class); - /** - * The source object. - */ - protected Object source; - - /** - * Load data, returns a list of items. - * - * @param registry The registry - * @param type The bean registry type - * @param source Introspected object or some other source - * - * @return a list of object names - * - * @throws Exception Error loading descriptors - */ - public abstract List<ObjectName> loadDescriptors(Registry registry, String type, Object source) throws Exception; + @Test + public void testDescriptorsAreRegisteredAndNoNamesReturned() throws Exception { + String type = "tester.TesterIntrospectionBean"; + Registry registry = Registry.getRegistry(null); + ModelerSource source = new MbeansDescriptorsIntrospectionSource(); + + List<ObjectName> result = + source.loadDescriptors(registry, type, TesterIntrospectionBean.class); + + // Descriptors are registered with the registry, no object names are + // returned + Assert.assertTrue(result.isEmpty()); + Assert.assertNotNull(registry.findManagedBean(type)); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
