This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 9af7f35d8f Trivial fixes from code review
9af7f35d8f is described below

commit 9af7f35d8f3f2d41fb9fdfe86f7ea3e0c6570ba8
Author: remm <[email protected]>
AuthorDate: Mon Jun 29 21:47:37 2026 +0200

    Trivial fixes from code review
    
    The FailedContext changes are not necessary, but what if.
    Make some package private fields private instead (some came from a
    strange commit from Violeta from code review back then - was complaining
    that protected inside a final class did not make sense).
---
 java/org/apache/catalina/startup/Catalina.java     |  1 +
 .../catalina/startup/CatalinaProperties.java       |  4 +-
 .../catalina/startup/ClassLoaderFactory.java       |  2 +-
 .../org/apache/catalina/startup/ContextConfig.java | 44 ++++++++--------------
 .../apache/catalina/startup/ContextRuleSet.java    |  2 +
 .../catalina/startup/CredentialHandlerRuleSet.java |  2 +-
 .../org/apache/catalina/startup/FailedContext.java | 39 +++++++++----------
 java/org/apache/catalina/startup/HostConfig.java   |  2 +-
 .../catalina/startup/ListenerCreateRule.java       |  2 +-
 .../catalina/startup/LocalStrings.properties       |  2 +
 .../apache/catalina/startup/SetNextNamingRule.java | 10 +++--
 java/org/apache/catalina/startup/Tomcat.java       |  2 +-
 java/org/apache/catalina/startup/UserConfig.java   | 12 +++---
 13 files changed, 60 insertions(+), 64 deletions(-)

diff --git a/java/org/apache/catalina/startup/Catalina.java 
b/java/org/apache/catalina/startup/Catalina.java
index fda29aa857..cf6f86c05c 100644
--- a/java/org/apache/catalina/startup/Catalina.java
+++ b/java/org/apache/catalina/startup/Catalina.java
@@ -781,6 +781,7 @@ public class Catalina {
         if (loaded) {
             return;
         }
+        // No load retry after a failure
         loaded = true;
 
         long t1 = System.nanoTime();
diff --git a/java/org/apache/catalina/startup/CatalinaProperties.java 
b/java/org/apache/catalina/startup/CatalinaProperties.java
index 423ab21e7a..3af942d42b 100644
--- a/java/org/apache/catalina/startup/CatalinaProperties.java
+++ b/java/org/apache/catalina/startup/CatalinaProperties.java
@@ -72,8 +72,8 @@ public class CatalinaProperties {
         try {
             String configUrl = System.getProperty("catalina.config");
             if (configUrl != null) {
-                if (configUrl.indexOf('/') == -1) {
-                    // No '/'. Must be a file name rather than a URL
+                if (configUrl.indexOf(':') == -1) {
+                    // No ':'. Must be a file name rather than a URL
                     fileName = configUrl;
                 } else {
                     is = new URI(configUrl).toURL().openStream();
diff --git a/java/org/apache/catalina/startup/ClassLoaderFactory.java 
b/java/org/apache/catalina/startup/ClassLoaderFactory.java
index 3eb01dcc2f..bd0c8a9ab8 100644
--- a/java/org/apache/catalina/startup/ClassLoaderFactory.java
+++ b/java/org/apache/catalina/startup/ClassLoaderFactory.java
@@ -43,7 +43,7 @@ import org.apache.juli.logging.LogFactory;
  * repositories.</li>
  * <li>A set of directories containing classes and resources in JAR files. 
Each readable JAR file discovered in these
  * directories will be added to the class loader's repositories.</li>
- * <li><code>ClassLoader</code> instance that should become the parent of the 
new class loader.</li>
+ * <li>{@link java.lang.ClassLoader} instance that should become the parent of 
the new class loader.</li>
  * </ul>
  */
 public final class ClassLoaderFactory {
diff --git a/java/org/apache/catalina/startup/ContextConfig.java 
b/java/org/apache/catalina/startup/ContextConfig.java
index 081f734b30..5235a692fe 100644
--- a/java/org/apache/catalina/startup/ContextConfig.java
+++ b/java/org/apache/catalina/startup/ContextConfig.java
@@ -698,8 +698,12 @@ public class ContextConfig implements LifecycleListener {
                     if (generateCode) {
                         contextXmlJavaSource =
                                 getContextXmlJavaSource(contextXmlPackageName, 
contextXmlSimpleClassName);
-                        digester.startGeneratingCode();
-                        generateClassHeader(digester, contextXmlPackageName, 
contextXmlSimpleClassName);
+                        if (contextXmlJavaSource != null) {
+                            digester.startGeneratingCode();
+                            generateClassHeader(digester, 
contextXmlPackageName, contextXmlSimpleClassName);
+                        } else {
+                            generateCode = false;
+                        }
                     }
                     URL defaultContextUrl = 
contextXmlResource.getURI().toURL();
                     processContextConfig(digester, defaultContextUrl, 
contextXmlResource.getInputStream());
@@ -737,8 +741,12 @@ public class ContextConfig implements LifecycleListener {
             } else if (!useGeneratedCode) {
                 if (generateCode) {
                     contextXmlJavaSource = 
getContextXmlJavaSource(contextXmlPackageName, contextXmlSimpleClassName);
-                    digester.startGeneratingCode();
-                    generateClassHeader(digester, contextXmlPackageName, 
contextXmlSimpleClassName);
+                    if (contextXmlJavaSource != null) {
+                        digester.startGeneratingCode();
+                        generateClassHeader(digester, contextXmlPackageName, 
contextXmlSimpleClassName);
+                    } else {
+                        generateCode = false;
+                    }
                 }
                 processContextConfig(digester, context.getConfigFile(), null);
                 if (generateCode) {
@@ -1023,7 +1031,7 @@ public class ContextConfig implements LifecycleListener {
 
 
     /**
-     * Process a "contextConfig" event for this Context.
+     * Process a "configure_start" event for this Context.
      */
     protected synchronized void configureStart() {
         // Called from StandardContext.start()
@@ -1079,7 +1087,7 @@ public class ContextConfig implements LifecycleListener {
 
 
     /**
-     * Process a "stop" event for this Context.
+     * Process a "configure_stop" event for this Context.
      */
     protected synchronized void configureStop() {
 
@@ -1696,44 +1704,24 @@ public class ContextConfig implements LifecycleListener 
{
         long hostTimeStamp = 0;
 
         if (globalWebXml != null) {
-            URLConnection uc = null;
             try {
                 URI uri = new URI(globalWebXml.getSystemId());
                 URL url = uri.toURL();
-                uc = url.openConnection();
+                URLConnection uc = url.openConnection();
                 globalTimeStamp = uc.getLastModified();
             } catch (IOException | URISyntaxException | 
IllegalArgumentException e) {
                 globalTimeStamp = -1;
-            } finally {
-                if (uc != null) {
-                    try {
-                        uc.getInputStream().close();
-                    } catch (IOException ioe) {
-                        ExceptionUtils.handleThrowable(ioe);
-                        globalTimeStamp = -1;
-                    }
-                }
             }
         }
 
         if (hostWebXml != null) {
-            URLConnection uc = null;
             try {
                 URI uri = new URI(hostWebXml.getSystemId());
                 URL url = uri.toURL();
-                uc = url.openConnection();
+                URLConnection uc = url.openConnection();
                 hostTimeStamp = uc.getLastModified();
             } catch (IOException | URISyntaxException | 
IllegalArgumentException e) {
                 hostTimeStamp = -1;
-            } finally {
-                if (uc != null) {
-                    try {
-                        uc.getInputStream().close();
-                    } catch (IOException ioe) {
-                        ExceptionUtils.handleThrowable(ioe);
-                        hostTimeStamp = -1;
-                    }
-                }
             }
         }
 
diff --git a/java/org/apache/catalina/startup/ContextRuleSet.java 
b/java/org/apache/catalina/startup/ContextRuleSet.java
index da8a4cfe14..6dccb9b6f0 100644
--- a/java/org/apache/catalina/startup/ContextRuleSet.java
+++ b/java/org/apache/catalina/startup/ContextRuleSet.java
@@ -42,6 +42,7 @@ public class ContextRuleSet implements RuleSet {
 
     /**
      * Construct an instance of this <code>RuleSet</code> with the default 
matching pattern prefix.
+     * The context instance will be created by the digester.
      */
     public ContextRuleSet() {
         this("");
@@ -50,6 +51,7 @@ public class ContextRuleSet implements RuleSet {
 
     /**
      * Construct an instance of this <code>RuleSet</code> with the specified 
matching pattern prefix.
+     * The context instance will be created by the digester.
      *
      * @param prefix Prefix for matching pattern rules (including the trailing 
slash character)
      */
diff --git a/java/org/apache/catalina/startup/CredentialHandlerRuleSet.java 
b/java/org/apache/catalina/startup/CredentialHandlerRuleSet.java
index defd44d63c..f6acdddf31 100644
--- a/java/org/apache/catalina/startup/CredentialHandlerRuleSet.java
+++ b/java/org/apache/catalina/startup/CredentialHandlerRuleSet.java
@@ -21,7 +21,7 @@ import org.apache.tomcat.util.digester.RuleSet;
 
 /**
  * <strong>RuleSet</strong> for processing the contents of a CredentialHandler 
definition element. This
- * <code>RuleSet</code> supports CredentialHandler such as the 
<code>NestedCredentialHandler</code> that used nested
+ * <code>RuleSet</code> supports CredentialHandler such as the 
<code>NestedCredentialHandler</code> that uses nested
  * CredentialHandlers.
  */
 public class CredentialHandlerRuleSet implements RuleSet {
diff --git a/java/org/apache/catalina/startup/FailedContext.java 
b/java/org/apache/catalina/startup/FailedContext.java
index 78935d7150..29b7492a2a 100644
--- a/java/org/apache/catalina/startup/FailedContext.java
+++ b/java/org/apache/catalina/startup/FailedContext.java
@@ -19,6 +19,7 @@ package org.apache.catalina.startup;
 import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.net.URL;
+import java.util.Collections;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
@@ -386,7 +387,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public ContainerListener[] findContainerListeners() {
-        return null;
+        return new ContainerListener[0];
     }
 
     @Override
@@ -441,7 +442,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public Object[] getApplicationEventListeners() {
-        return null;
+        return new Object[0];
     }
 
     @Override
@@ -451,7 +452,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public Object[] getApplicationLifecycleListeners() {
-        return null;
+        return new Object[0];
     }
 
     @Override
@@ -776,7 +777,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public String[] findApplicationListeners() {
-        return null;
+        return new String[0];
     }
 
     @Override
@@ -791,7 +792,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public ApplicationParameter[] findApplicationParameters() {
-        return null;
+        return new ApplicationParameter[0];
     }
 
     @Override
@@ -806,7 +807,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public SecurityConstraint[] findConstraints() {
-        return null;
+        return new SecurityConstraint[0];
     }
 
     @Override
@@ -836,7 +837,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public ErrorPage[] findErrorPages() {
-        return null;
+        return new ErrorPage[0];
     }
 
     @Override
@@ -856,7 +857,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public FilterDef[] findFilterDefs() {
-        return null;
+        return new FilterDef[0];
     }
 
     @Override
@@ -876,7 +877,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public FilterMap[] findFilterMaps() {
-        return null;
+        return new FilterMap[0];
     }
 
     @Override
@@ -901,7 +902,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public String[] findMimeMappings() {
-        return null;
+        return new String[0];
     }
 
     @Override
@@ -921,7 +922,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public String[] findParameters() {
-        return null;
+        return new String[0];
     }
 
     @Override
@@ -956,7 +957,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public String[] findSecurityRoles() {
-        return null;
+        return new String[0];
     }
 
     @Override
@@ -976,7 +977,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public String[] findServletMappings() {
-        return null;
+        return new String[0];
     }
 
     @Override
@@ -996,7 +997,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public String[] findWelcomeFiles() {
-        return null;
+        return new String[0];
     }
 
     @Override
@@ -1011,7 +1012,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public String[] findWrapperLifecycles() {
-        return null;
+        return new String[0];
     }
 
     @Override
@@ -1026,7 +1027,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public String[] findWrapperListeners() {
-        return null;
+        return new String[0];
     }
 
     @Override
@@ -1122,7 +1123,7 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
     @Override
     public Set<String> addServletSecurity(ServletRegistration.Dynamic 
registration,
             ServletSecurityElement servletSecurityElement) {
-        return null;
+        return Collections.emptySet();
     }
 
     @Override
@@ -1236,12 +1237,12 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
 
     @Override
     public Map<String,String> findPostConstructMethods() {
-        return null;
+        return Collections.emptyMap();
     }
 
     @Override
     public Map<String,String> findPreDestroyMethods() {
-        return null;
+        return Collections.emptyMap();
     }
 
     @Override
diff --git a/java/org/apache/catalina/startup/HostConfig.java 
b/java/org/apache/catalina/startup/HostConfig.java
index e04c9cc19d..79cf243f07 100644
--- a/java/org/apache/catalina/startup/HostConfig.java
+++ b/java/org/apache/catalina/startup/HostConfig.java
@@ -388,7 +388,7 @@ public class HostConfig implements LifecycleListener {
 
 
     /**
-     * Removed a serviced application from the list.
+     * Remove a serviced application from the list.
      *
      * @param name the context name
      */
diff --git a/java/org/apache/catalina/startup/ListenerCreateRule.java 
b/java/org/apache/catalina/startup/ListenerCreateRule.java
index a8774f74db..81f863394e 100644
--- a/java/org/apache/catalina/startup/ListenerCreateRule.java
+++ b/java/org/apache/catalina/startup/ListenerCreateRule.java
@@ -127,7 +127,7 @@ public class ListenerCreateRule extends ObjectCreateRule {
         }
 
         /**
-         * Return a property from the protocol handler.
+         * Return a property from the listener.
          *
          * @param name the property name
          *
diff --git a/java/org/apache/catalina/startup/LocalStrings.properties 
b/java/org/apache/catalina/startup/LocalStrings.properties
index 2051212dd8..c519bc2d2f 100644
--- a/java/org/apache/catalina/startup/LocalStrings.properties
+++ b/java/org/apache/catalina/startup/LocalStrings.properties
@@ -164,6 +164,8 @@ listener.notServer=This listener must only be nested within 
Server elements, but
 
 passwdUserDatabase.readFail=Failed to obtain a complete set of users from 
/etc/passwd
 
+setNextNamingRule.invalidParent=Parent should be either a Context or a 
NamingResources
+
 tomcat.addWebapp.conflictChild=Unable to deploy WAR at [{0}] to context path 
[{1}] because of existing context [{2}]
 tomcat.addWebapp.conflictFile=Unable to deploy WAR at [{0}] to context path 
[{1}] because of existing file [{2}]
 tomcat.baseDirMakeFail=Unable to create the directory [{0}] to use as the base 
directory
diff --git a/java/org/apache/catalina/startup/SetNextNamingRule.java 
b/java/org/apache/catalina/startup/SetNextNamingRule.java
index 1d07c18ebe..c13571ed21 100644
--- a/java/org/apache/catalina/startup/SetNextNamingRule.java
+++ b/java/org/apache/catalina/startup/SetNextNamingRule.java
@@ -17,8 +17,8 @@
 package org.apache.catalina.startup;
 
 import org.apache.catalina.Context;
-import org.apache.catalina.deploy.NamingResourcesImpl;
 import org.apache.tomcat.util.IntrospectionUtils;
+import org.apache.tomcat.util.descriptor.web.NamingResources;
 import org.apache.tomcat.util.digester.Rule;
 
 
@@ -78,12 +78,14 @@ public class SetNextNamingRule extends Rule {
         Object parent = digester.peek(1);
         boolean context = false;
 
-        NamingResourcesImpl namingResources;
+        NamingResources namingResources;
         if (parent instanceof Context) {
             namingResources = ((Context) parent).getNamingResources();
             context = true;
+        } else if (parent instanceof NamingResources) {
+            namingResources = (NamingResources) parent;
         } else {
-            namingResources = (NamingResourcesImpl) parent;
+            throw new 
IllegalArgumentException(sm.getString("setNextNamingRule.invalidParent"));
         }
 
         // Call the specified method
@@ -105,7 +107,7 @@ public class SetNextNamingRule extends Rule {
 
     @Override
     public String toString() {
-        return "SetNextRule[" + "methodName=" + methodName + ", paramType=" + 
paramType + ']';
+        return "SetNextNamingRule[" + "methodName=" + methodName + ", 
paramType=" + paramType + ']';
     }
 
 
diff --git a/java/org/apache/catalina/startup/Tomcat.java 
b/java/org/apache/catalina/startup/Tomcat.java
index 98243edecd..ed7a7c5619 100644
--- a/java/org/apache/catalina/startup/Tomcat.java
+++ b/java/org/apache/catalina/startup/Tomcat.java
@@ -867,7 +867,7 @@ public class Tomcat {
         System.setProperty(Globals.CATALINA_HOME_PROP, 
server.getCatalinaHome().getPath());
     }
 
-    static final String[] silences =
+    private static final String[] silences =
             new String[] { "org.apache.coyote.http11.Http11NioProtocol", 
"org.apache.catalina.core.StandardService",
                     "org.apache.catalina.core.StandardEngine", 
"org.apache.catalina.startup.ContextConfig",
                     "org.apache.catalina.core.ApplicationContext", 
"org.apache.catalina.core.AprLifecycleListener" };
diff --git a/java/org/apache/catalina/startup/UserConfig.java 
b/java/org/apache/catalina/startup/UserConfig.java
index 1c65ec5199..de8618395f 100644
--- a/java/org/apache/catalina/startup/UserConfig.java
+++ b/java/org/apache/catalina/startup/UserConfig.java
@@ -97,14 +97,14 @@ public final class UserConfig implements LifecycleListener {
     private String userClass = 
"org.apache.catalina.startup.PasswdUserDatabase";
 
     /**
-     * A regular expression defining user who deployment is allowed.
+     * A regular expression defining users for whom deployment is allowed.
      */
-    Pattern allow = null;
+    private Pattern allow = null;
 
     /**
-     * A regular expression defining user who deployment is denied.
+     * A regular expression defining users for whom deployment is denied.
      */
-    Pattern deny = null;
+    private Pattern deny = null;
 
     // ------------------------------------------------------------- Properties
 
@@ -222,7 +222,7 @@ public final class UserConfig implements LifecycleListener {
 
 
     /**
-     * Set the regular expression used to test for user who deployment is 
allowed.
+     * Set the regular expression used to test for users for whom deployment 
is allowed.
      *
      * @param allow The new allow expression
      */
@@ -249,7 +249,7 @@ public final class UserConfig implements LifecycleListener {
 
 
     /**
-     * Set the regular expression used to test for user who deployment is 
denied.
+     * Set the regular expression used to test for users for whom deployment 
is denied.
      *
      * @param deny The new deny expression
      */


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to