Repository: logging-log4j2 Updated Branches: refs/heads/master ae7f1256c -> b562b0717
[LOG4J2-2270] Strings::join, when called with [null] returns "null" instead of EMPTY. I implemented a different fix than the one proposed in the PR. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b562b071 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b562b071 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b562b071 Branch: refs/heads/master Commit: b562b07177efb0f4b7f3bf5b55c2b123414f6743 Parents: ae7f125 Author: Gary Gregory <[email protected]> Authored: Sun Feb 25 11:05:08 2018 -0700 Committer: Gary Gregory <[email protected]> Committed: Sun Feb 25 11:05:08 2018 -0700 ---------------------------------------------------------------------- .../org/apache/logging/log4j/util/Strings.java | 2 +- .../apache/logging/log4j/util/StringsTest.java | 19 +++++++++++++++++++ src/changes/changes.xml | 5 ++++- 3 files changed, 24 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b562b071/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java index f6608d6..c369a4e 100644 --- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java @@ -216,7 +216,7 @@ public final class Strings { } final Object first = iterator.next(); if (!iterator.hasNext()) { - return Objects.toString(first); + return Objects.toString(first, EMPTY); } // two or more elements http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b562b071/log4j-api/src/test/java/org/apache/logging/log4j/util/StringsTest.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/StringsTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/StringsTest.java index d516739..162d162 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/util/StringsTest.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/StringsTest.java @@ -20,6 +20,9 @@ package org.apache.logging.log4j.util; import org.junit.Assert; import org.junit.Test; +import java.util.Arrays; +import java.util.Iterator; + public class StringsTest { /** @@ -32,6 +35,22 @@ public class StringsTest { } @Test + public void testJoin() { + Assert.assertEquals(null, Strings.join((Iterable<?>) null, '.')); + Assert.assertEquals(null, Strings.join((Iterator<?>) null, '.')); + Assert.assertEquals("", Strings.join((Arrays.asList()), '.')); + + Assert.assertEquals("a", Strings.join(Arrays.asList("a"), '.')); + Assert.assertEquals("a.b", Strings.join(Arrays.asList("a", "b"), '.')); + Assert.assertEquals("a.b.c", Strings.join(Arrays.asList("a", "b", "c"), '.')); + + Assert.assertEquals("", Strings.join(Arrays.asList((String) null), ':')); + Assert.assertEquals(":", Strings.join(Arrays.asList(null, null), ':')); + Assert.assertEquals("a:", Strings.join(Arrays.asList("a", null), ':')); + Assert.assertEquals(":b", Strings.join(Arrays.asList(null, "b"), ':')); + } + + @Test public void testQuote() { Assert.assertEquals("'Q'", Strings.quote("Q")); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b562b071/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3b5d1d5..f0a538a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -58,7 +58,7 @@ <action issue="LOG4J2-2233" dev="ggregory" type="update" due-to="Gary Gregory"> Move JDBC code to a new module log4j-jdbc. </action> - <action issue="LOG4J2-2244" dev="ggregory" type="update" due-to="Gary Gregory"> + <action issue="LOG4J2-2244" dev="ggregory" type="fix" due-to="Gary Gregory"> org.apache.logging.log4j.core.lookup.EnvironmentLookup may throw NPE. </action> <action issue="LOG4J2-2237" dev="ggregory" type="update" due-to="Gary Gregory"> @@ -85,6 +85,9 @@ <action issue="LOG4J2-2260" dev="ggregory" type="update"> [SMTP] Update javax.mail from 1.6.0 to 1.6.1. </action> + <action issue="LOG4J2-2270" dev="ggregory" type="fix" due-to="Cyril Martin"> + Strings::join, when called with [null] returns "null" instead of EMPTY. + </action> </release> <release version="2.11.0" date="2018-xx-xx" description="GA Release 2.11.0"> <action issue="LOG4J2-2254" dev="rgoers" type="fix">
