This is an automated email from the ASF dual-hosted git repository. pkarwasz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit cf32904e3e0cf165d096ba00b14872c1fcebfd92 Author: Piotr P. Karwasz <[email protected]> AuthorDate: Thu Jun 9 14:51:02 2022 +0200 [LOG4J2-3531] Check if XInclude is supported Xerces does not check if XInclude is supported until the `DocumentBuilderFactory` is instantiated. --- .../logging/log4j/core/config/xml/XmlConfiguration.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java index 5e5d653b83..8cf8631629 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java @@ -202,9 +202,6 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu private static void setFeature(final DocumentBuilderFactory factory, final String featureName, final boolean value) { try { factory.setFeature(featureName, value); - // LOG4J2-3531: Xerces only throw when creating a factory. - // In newer versions 'setFeature' does this automatically. - factory.newDocumentBuilder(); } catch (final ParserConfigurationException e) { LOGGER.warn("The DocumentBuilderFactory [{}] does not support the feature [{}]: {}", factory, featureName, e); @@ -224,9 +221,13 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu // Alternative: We set if a system property on the command line is set, for example: // -DLog4j.XInclude=true factory.setXIncludeAware(true); - } catch (final UnsupportedOperationException e) { + // LOG4J2-3531: Xerces only checks if the feature is supported when creating a factory. To reproduce: + // -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XML11NonValidatingConfiguration + factory.newDocumentBuilder(); + } catch (final UnsupportedOperationException | ParserConfigurationException e) { + factory.setXIncludeAware(false); LOGGER.warn("The DocumentBuilderFactory [{}] does not support XInclude: {}", factory, e); - } catch (@SuppressWarnings("ErrorNotRethrown") final AbstractMethodError | NoSuchMethodError err) { + } catch (final AbstractMethodError | NoSuchMethodError err) { LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support XInclude: {}", factory, err); }
