StringUtils.join(Iterator, String) should only return null when the
Iterator is null
This commit is contained in:
parent
6a95f03a6a
commit
39f08ac62f
|
@ -90,6 +90,7 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<action type="fix" dev="ggregory" due-to="guicaiyue">Javadoc: StringUtils.repeat("", "x", 3) = "xx"; #918.</action>
|
||||
<action type="fix" dev="ggregory" due-to="Marc Wrobel">Fix typos #920, #923.</action>
|
||||
<action type="fix" dev="ggregory" due-to="Bhimantoro Suryo Admodjo">Simplify condition #925.</action>
|
||||
<action type="fix" dev="ggregory" due-to="Gary Gregory">StringUtils.join(Iterator, String) should only return null when the Iterator is null.</action>
|
||||
<!-- ADD -->
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GitHub coverage.yml.</action>
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add EnumUtils.getEnumSystemProperty(...).</action>
|
||||
|
@ -160,7 +161,7 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<action issue="LANG-1662" type="add" dev="ggregory" due-to="Daniel Augusto Veronezi Salvador, Gary Gregory, Bruno P. Kinoshita">Let ReflectionToStringBuilder only reflect given field names #849.</action>
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.of(Enumeration<E>).</action>
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.of(Iterable<E>).</action>
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add LangCollectors.</action>
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.of(Iterator<E>).</action>
|
||||
<!-- UPDATE -->
|
||||
<action type="update" dev="ggregory" due-to="Dependabot, XenoAmess, Gary Gregory">Bump actions/cache from 2.1.4 to 3.0.7 #742, #752, #764, #833, #867.</action>
|
||||
<action type="update" dev="ggregory" due-to="Dependabot">Bump actions/checkout from 2 to 3 #819, #825, #859.</action>
|
||||
|
|
|
@ -4350,10 +4350,7 @@ public class StringUtils {
|
|||
* @since 2.3
|
||||
*/
|
||||
public static String join(final Iterable<?> iterable, final char separator) {
|
||||
if (iterable == null) {
|
||||
return null;
|
||||
}
|
||||
return join(iterable.iterator(), separator);
|
||||
return iterable != null ? join(iterable.iterator(), separator) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4371,10 +4368,7 @@ public class StringUtils {
|
|||
* @since 2.3
|
||||
*/
|
||||
public static String join(final Iterable<?> iterable, final String separator) {
|
||||
if (iterable == null) {
|
||||
return null;
|
||||
}
|
||||
return join(iterable.iterator(), separator);
|
||||
return iterable != null ? join(iterable.iterator(), separator) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4436,7 +4430,6 @@ public class StringUtils {
|
|||
* @return the joined String, {@code null} if null iterator input
|
||||
*/
|
||||
public static String join(final Iterator<?> iterator, final String separator) {
|
||||
|
||||
// handle null, zero and one elements before building a buffer
|
||||
if (iterator == null) {
|
||||
return null;
|
||||
|
@ -4444,25 +4437,18 @@ public class StringUtils {
|
|||
if (!iterator.hasNext()) {
|
||||
return EMPTY;
|
||||
}
|
||||
final Object first = iterator.next();
|
||||
if (!iterator.hasNext()) {
|
||||
return Objects.toString(first, "");
|
||||
}
|
||||
|
||||
// two or more elements
|
||||
final StringBuilder buf = new StringBuilder(STRING_BUILDER_SIZE); // Java default is 16, probably too small
|
||||
if (first != null) {
|
||||
buf.append(first);
|
||||
}
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
if (separator != null) {
|
||||
buf.append(separator);
|
||||
}
|
||||
final Object obj = iterator.next();
|
||||
if (obj != null) {
|
||||
buf.append(obj);
|
||||
}
|
||||
if (separator != null && iterator.hasNext()) {
|
||||
buf.append(separator);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
|
|
@ -1310,7 +1310,7 @@ public class StringUtilsTest extends AbstractLangTest {
|
|||
|
||||
assertEquals(TEXT_LIST, StringUtils.join(Arrays.asList(ARRAY_LIST).iterator(), SEPARATOR));
|
||||
|
||||
assertNull(StringUtils.join(Arrays.asList(NULL_TO_STRING_LIST).iterator(), SEPARATOR));
|
||||
assertEquals("null", StringUtils.join(Arrays.asList(NULL_TO_STRING_LIST).iterator(), SEPARATOR));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue