This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit f5bd70a04267bc66205829e86324847ee9dc664c 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 9fccd90b3f..7c9ad39d31 100644 --- a/java/org/apache/catalina/startup/ContextConfig.java +++ b/java/org/apache/catalina/startup/ContextConfig.java @@ -777,22 +777,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]
