[LOG4J2-2001] StyleConverter.newInstance argument validation is incorrect. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/80a49632 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/80a49632 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/80a49632
Branch: refs/heads/LOG4J2-1431 Commit: 80a496327fc0ae7b33308b114d034ff91699f595 Parents: 303e448 Author: Gary Gregory <[email protected]> Authored: Mon Aug 21 13:45:05 2017 -0600 Committer: Gary Gregory <[email protected]> Committed: Mon Aug 21 13:45:05 2017 -0600 ---------------------------------------------------------------------- .../apache/logging/log4j/core/pattern/StyleConverter.java | 9 ++++++--- .../logging/log4j/core/pattern/StyleConverterTest.java | 6 ++++++ src/changes/changes.xml | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a49632/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java index 821005a..acbf2b6 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java @@ -76,16 +76,19 @@ public final class StyleConverter extends LogEventPatternConverter implements An * @return instance of class. */ public static StyleConverter newInstance(final Configuration config, final String[] options) { - if (options.length < 1) { + if (options == null) { + return null; + } + if (options.length < 2) { LOGGER.error("Incorrect number of options on style. Expected at least 1, received " + options.length); return null; } if (options[0] == null) { - LOGGER.error("No pattern supplied on style"); + LOGGER.error("No pattern supplied for style converter"); return null; } if (options[1] == null) { - LOGGER.error("No style attributes provided"); + LOGGER.error("No style attributes supplied for style converter"); return null; } final PatternParser parser = PatternLayout.createPatternParser(config); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a49632/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java index 42d20a0..ea62885 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java @@ -22,6 +22,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.junit.LoggerContextRule; import org.apache.logging.log4j.test.appender.ListAppender; import org.apache.logging.log4j.util.Strings; +import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -58,4 +59,9 @@ public class StyleConverterTest { assertEquals("Incorrect number of messages. Should be 1 is " + msgs.size(), 1, msgs.size()); assertTrue("Replacement failed - expected ending " + EXPECTED + ", actual " + msgs.get(0), msgs.get(0).endsWith(EXPECTED)); } + + @Test + public void testNull() { + Assert.assertNull(StyleConverter.newInstance(null, null)); + } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a49632/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 130a4c6..5ebf604 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -40,6 +40,9 @@ <action issue="LOG4J2-2018" dev="rpopma" type="fix"> Fix incorrect documentation for LoggerNameLevelRewritePolicy. </action> + <action issue="LOG4J2-2001" dev="ggregory" type="fix" due-to="Paul Burrowes"> + StyleConverter.newInstance argument validation is incorrect. + </action> <action issue="LOG4J2-2013" dev="ggregory" type="fix" due-to="Taylor Patton, Gary Gregory"> SslSocketManager does not apply SSLContext on TCP reconnect. </action>
