Repository: logging-log4j2 Updated Branches: refs/heads/master d6391e98f -> 6f242922d
[LOG4J2-1127] log4j2.xml cannot be parsed on Oracle Weblogic 12c. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6f242922 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6f242922 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6f242922 Branch: refs/heads/master Commit: 6f242922d70135c4a5524d55dab187a7f5e34531 Parents: d6391e9 Author: ggregory <[email protected]> Authored: Tue Sep 22 13:31:59 2015 -0700 Committer: ggregory <[email protected]> Committed: Tue Sep 22 13:31:59 2015 -0700 ---------------------------------------------------------------------- .../log4j/core/config/xml/XmlConfiguration.java | 4 +++- .../logging/log4j/core/util/Throwables.java | 16 ++++++++++++++++ .../logging/log4j/core/util/ThrowablesTest.java | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6f242922/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java ---------------------------------------------------------------------- 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 2adc756..4712d9d 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 @@ -28,6 +28,7 @@ import org.apache.logging.log4j.core.config.status.StatusConfiguration; import org.apache.logging.log4j.core.util.Closer; import org.apache.logging.log4j.core.util.Loader; import org.apache.logging.log4j.core.util.Patterns; +import org.apache.logging.log4j.core.util.Throwables; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -145,7 +146,8 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu document = documentBuilder.parse(source); } catch (final Exception e) { // LOG4J2-1127 - if (e.getCause() instanceof UnsupportedOperationException) { + Throwable throwable = Throwables.getRootCause(e); + if (throwable instanceof UnsupportedOperationException) { LOGGER.warn( "The DocumentBuilder {} does not support an operation: {}. Trying again without XInclude...", documentBuilder, e); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6f242922/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java index a852772..261932c 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java @@ -46,6 +46,22 @@ public final class Throwables { } /** + * Returns the deepest cause of the given {@code throwable}. + * + * @param throwable + * the throwable to navigate + * @return the deepest throwable or the given throwable + */ + public static Throwable getRootCause(final Throwable throwable) { + Throwable cause; + Throwable root = throwable; + while ((cause = root.getCause()) != null) { + root = cause; + } + return root; + } + + /** * Has no effect on Java 6 and below. * * @param throwable a Throwable http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6f242922/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ThrowablesTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ThrowablesTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ThrowablesTest.java index 2a58353..50d462c 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ThrowablesTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ThrowablesTest.java @@ -22,6 +22,25 @@ import org.junit.Test; public class ThrowablesTest { + @Test + public void testGetRootCauseNone() throws Exception { + final NullPointerException throwable = new NullPointerException(); + org.junit.Assert.assertEquals(throwable, Throwables.getRootCause(throwable)); + } + + @Test + public void testGetRootCauseDepth1() throws Exception { + final NullPointerException throwable = new NullPointerException(); + org.junit.Assert.assertEquals(throwable, Throwables.getRootCause(new UnsupportedOperationException(throwable))); + } + + @Test + public void testGetRootCauseDepth2() throws Exception { + final NullPointerException throwable = new NullPointerException(); + org.junit.Assert.assertEquals(throwable, + Throwables.getRootCause(new IllegalArgumentException(new UnsupportedOperationException(throwable)))); + } + @Test(expected = NullPointerException.class) public void testRethrowRuntimeException() throws Exception { Throwables.rethrow(new NullPointerException());
