You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2026/10/08 16:12:35 UTC
(tomcat) 15/22: Skip parsing a context configuration file that cannot be opened
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
commit 55e07fdf7e568cf1ed0a5f7cd5ef281a93d0cdd4
Author: opencode <re...@apache.org>
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 be46dfb836..21db7ad4a7 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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org