StringUtils.join(Iterator, String) should only return null when the
Iterator is null
This commit is contained in:
parent
39f08ac62f
commit
ec93f3b7f5
|
@ -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(Iterable, String) should only return null when the Iterable is null.</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>
|
||||
|
|
|
@ -4394,23 +4394,19 @@ public class StringUtils {
|
|||
if (!iterator.hasNext()) {
|
||||
return EMPTY;
|
||||
}
|
||||
final Object first = iterator.next();
|
||||
if (!iterator.hasNext()) {
|
||||
return toStringOrEmpty(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()) {
|
||||
buf.append(separator);
|
||||
final Object obj = iterator.next();
|
||||
if (obj != null) {
|
||||
buf.append(obj);
|
||||
}
|
||||
if (iterator.hasNext()) {
|
||||
buf.append(separator);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
|
|
|
@ -1292,6 +1292,7 @@ public class StringUtilsTest extends AbstractLangTest {
|
|||
assertEquals("", StringUtils.join(Arrays.asList(NULL_ARRAY_LIST).iterator(), SEPARATOR_CHAR));
|
||||
assertEquals("", StringUtils.join(Arrays.asList(EMPTY_ARRAY_LIST).iterator(), SEPARATOR_CHAR));
|
||||
assertEquals("foo", StringUtils.join(Collections.singleton("foo").iterator(), 'x'));
|
||||
assertEquals("null", StringUtils.join(Arrays.asList(NULL_TO_STRING_LIST).iterator(), SEPARATOR_CHAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue