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 2d00a7013e2137a91da4ad4468f63b93bfafa6a7
Author: opencode <[email protected]>
AuthorDate: Thu Oct 8 15:48:47 2026 +0200

    Skip parsing a context configuration file that cannot be opened
    
    In processContextConfig() the InputSource was created before the
    input stream for the configuration file was opened, so the null check
    that guarded the parse was unreachable. When opening the file failed,
    for example an external context configuration file that does not
    exist, processing continued into digester.parse() with a byte-stream
    less InputSource, the SAX parser re-resolved the same URL and failed
    again, logging a second, duplicate error for the one problem.
    
    The stream is now opened before the InputSource is created. If
    opening fails, the single error is logged, the context is marked as
    not configured and parsing is skipped. The visible outcome for the
    deployment is unchanged; only the duplicate error output is removed.
---
 java/org/apache/catalina/startup/ContextConfig.java | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/java/org/apache/catalina/startup/ContextConfig.java 
b/java/org/apache/catalina/startup/ContextConfig.java
index 53c638bae0..b9f95810da 100644
--- a/java/org/apache/catalina/startup/ContextConfig.java
+++ b/java/org/apache/catalina/startup/ContextConfig.java
@@ -779,22 +779,21 @@ public class ContextConfig implements LifecycleListener {
             log.debug(sm.getString("contextConfig.processContext", 
context.getName(), contextXml));
         }
 
-        InputSource source = null;
+        InputSource source;
 
-        try {
-            source = new InputSource(contextXml.toString());
-            if (stream == null) {
+        if (stream == null) {
+            try {
                 URLConnection xmlConn = contextXml.openConnection();
                 xmlConn.setUseCaches(false);
                 stream = xmlConn.getInputStream();
+            } catch (Exception e) {
+                log.error(sm.getString("contextConfig.contextMissing", 
contextXml), e);
+                ok = false;
+                return;
             }
-        } catch (Exception e) {
-            log.error(sm.getString("contextConfig.contextMissing", 
contextXml), e);
         }
 
-        if (source == null) {
-            return;
-        }
+        source = new InputSource(contextXml.toString());
 
         try {
             source.setByteStream(stream);


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

Reply via email to