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/09/30 03:02:41 UTC
[logging-log4j2] branch master updated (f1c9991902 -> 776263e39b)
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
from f1c9991902 Fix compile scope of `log4j-jndi-test`
new 430ff52057 [LOG4J2-3531] Parser configuration workaround for old Xerces
new cf32904e3e [LOG4J2-3531] Check if XInclude is supported
new 776263e39b Use `Integers` util class
The 3 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.
Summary of changes:
.../log4j/core/config/xml/XmlConfiguration.java | 77 ++++++++++------------
1 file changed, 34 insertions(+), 43 deletions(-)
[logging-log4j2] 02/03: [LOG4J2-3531] Check if XInclude is supported
Posted by pk...@apache.org.
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 <pi...@karwasz.org>
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);
}
[logging-log4j2] 03/03: Use `Integers` util class
Posted by pk...@apache.org.
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 776263e39bb05b571ce442f2b45749fbdcad37f2
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Fri Sep 30 05:02:03 2022 +0200
Use `Integers` util class
---
.../log4j/core/config/xml/XmlConfiguration.java | 38 ++++++++++++----------
1 file changed, 20 insertions(+), 18 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 8cf8631629..ad1667800d 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
@@ -16,6 +16,24 @@
*/
package org.apache.logging.log4j.core.config.xml;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.AbstractConfiguration;
import org.apache.logging.log4j.core.config.Configuration;
@@ -23,6 +41,7 @@ import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Reconfigurable;
import org.apache.logging.log4j.core.config.status.StatusConfiguration;
import org.apache.logging.log4j.core.util.Closer;
+import org.apache.logging.log4j.core.util.Integers;
import org.apache.logging.log4j.core.util.Loader;
import org.apache.logging.log4j.core.util.Patterns;
import org.apache.logging.log4j.core.util.Throwables;
@@ -38,23 +57,6 @@ import org.w3c.dom.Text;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
/**
* Creates a Node hierarchy from an XML file.
*/
@@ -130,7 +132,7 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu
} else if ("schema".equalsIgnoreCase(key)) {
schemaResource = value;
} else if ("monitorInterval".equalsIgnoreCase(key)) {
- monitorIntervalSeconds = Integer.parseInt(value);
+ monitorIntervalSeconds = Integers.parseInt(value);
} else if ("advertiser".equalsIgnoreCase(key)) {
createAdvertiser(value, configSource, buffer, "text/xml");
}
[logging-log4j2] 01/03: [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 master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 430ff520575f359402883a5e118029f7ffc7d462
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 25ae2a715e..5e5d653b83 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,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 (final 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);
}
}
@@ -224,26 +230,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