This is an automated email from the ASF dual-hosted git repository.
remm 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 90017ebb70 Add new registry factory that does not return null
90017ebb70 is described below
commit 90017ebb7008fa2ee2db5607f396d4a2486a9997
Author: remm <[email protected]>
AuthorDate: Wed Mar 19 10:50:58 2025 +0100
Add new registry factory that does not return null
Adding null checks everywhere is not worth it.
---
.../tomcat/util/modeler/LocalStrings.properties | 1 +
java/org/apache/tomcat/util/modeler/Registry.java | 23 ++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/java/org/apache/tomcat/util/modeler/LocalStrings.properties
b/java/org/apache/tomcat/util/modeler/LocalStrings.properties
index d40f0527d8..a5464f7b04 100644
--- a/java/org/apache/tomcat/util/modeler/LocalStrings.properties
+++ b/java/org/apache/tomcat/util/modeler/LocalStrings.properties
@@ -40,6 +40,7 @@ managedMBean.noSet=Cannot find setter method [{0}] on
resource [{1}]
modules.digesterParseError=Error parsing registry data
modules.readDescriptorsError=Error reading descriptors
+registry.cannotAccessRegistry=Guard object [{0}] does not allow access to the
registry
registry.createdServer=Created MBeanServer
registry.existingServer=Using existing MBeanServer
registry.initError=Error initializing [{0}]
diff --git a/java/org/apache/tomcat/util/modeler/Registry.java
b/java/org/apache/tomcat/util/modeler/Registry.java
index 1db01647ab..be18708775 100644
--- a/java/org/apache/tomcat/util/modeler/Registry.java
+++ b/java/org/apache/tomcat/util/modeler/Registry.java
@@ -132,6 +132,29 @@ public class Registry implements RegistryMBean,
MBeanRegistration {
}
+ /**
+ * Factory method to create (if necessary) and return our
+ * <code>Registry</code> instance.
+ *
+ * @param key Unused
+ * @param guard Prevent access to the registry by untrusted components
+ *
+ * @return the registry
+ * @throws IllegalArgumentException if the guard object does not allow
access
+ * @since 1.1
+ */
+ public static synchronized Registry getRegistryNonNull(Object key, Object
guard) {
+ if (registry == null) {
+ registry = new Registry();
+ registry.guard = guard;
+ }
+ if (registry.guard != null && registry.guard != guard) {
+ throw new
IllegalArgumentException(sm.getString("registry.cannotAccessRegistry", guard));
+ }
+ return registry;
+ }
+
+
public static synchronized void disableRegistry() {
if (registry == null) {
registry = new NoDescriptorRegistry();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]