You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2022/06/08 17:29:36 UTC
[logging-log4j2] branch parser-configuration created (now d5a5ee7512)
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a change to branch parser-configuration
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
at d5a5ee7512 [LOG4J2-3531] Parser configuration workaround for old Xerces
This branch includes the following new commits:
new d5a5ee7512 [LOG4J2-3531] Parser configuration workaround for old Xerces
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[logging-log4j2] 01/01: [LOG4J2-3531] Parser configuration workaround for old Xerces
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch parser-configuration
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit d5a5ee7512c4b00e8fe69f533584a386ec1e1f46
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Wed Jun 8 19:29:20 2022 +0200
[LOG4J2-3531] Parser configuration workaround for old Xerces
Some versions of Xerces validate the requested features upon factory
instantiation, not when `setFeature` is called.
---
.../log4j/core/config/xml/XmlConfiguration.java | 34 +++++++---------------
1 file changed, 11 insertions(+), 23 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 649f013d08..519fc94b3d 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
@@ -204,9 +204,15 @@ 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);
- } catch (Exception | LinkageError e) {
- getStatusLogger().error("Caught {} setting feature {} to {} on DocumentBuilderFactory {}: {}",
- e.getClass().getCanonicalName(), featureName, value, factory, e, e);
+ // 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);
+ } catch (final AbstractMethodError err) {
+ LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support setFeature: {}", factory,
+ err);
}
}
@@ -226,26 +232,8 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu
LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support XInclude: {}", factory,
err);
}
- try {
- // Alternative: We could specify all features and values with system properties like:
- // -DLog4j.DocumentBuilderFactory.Feature="http://apache.org/xml/features/xinclude/fixup-base-uris true"
- factory.setFeature(XINCLUDE_FIXUP_BASE_URIS, true);
- } catch (final ParserConfigurationException e) {
- LOGGER.warn("The DocumentBuilderFactory [{}] does not support the feature [{}]: {}", factory,
- XINCLUDE_FIXUP_BASE_URIS, e);
- } catch (@SuppressWarnings("ErrorNotRethrown") final AbstractMethodError err) {
- LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support setFeature: {}", factory,
- err);
- }
- try {
- factory.setFeature(XINCLUDE_FIXUP_LANGUAGE, true);
- } catch (final ParserConfigurationException e) {
- LOGGER.warn("The DocumentBuilderFactory [{}] does not support the feature [{}]: {}", factory,
- XINCLUDE_FIXUP_LANGUAGE, e);
- } catch (@SuppressWarnings("ErrorNotRethrown") final AbstractMethodError err) {
- LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support setFeature: {}", factory,
- err);
- }
+ setFeature(factory, XINCLUDE_FIXUP_BASE_URIS, true);
+ setFeature(factory, XINCLUDE_FIXUP_LANGUAGE, true);
}
@Override