Fix collectionToDelimitedString failure for null elements.

Prior to this commit, calling `StringUtils#collectionToDelimitedString`
would fail with an NPE if the collection contains null elements.

This commit ensures that null elements are converted as `"null"` in the
resulting String without failure.

See gh-27419
This commit is contained in:
Koy 2021-09-16 16:13:29 +08:00 committed by Brian Clozel
parent 008aa48d5c
commit 0d6cc12274
1 changed files with 1 additions and 1 deletions

View File

@ -1301,7 +1301,7 @@ public abstract class StringUtils {
int totalLength = coll.size() * (prefix.length() + suffix.length()) + (coll.size() - 1) * delim.length();
for (Object element : coll) {
totalLength += element.toString().length();
totalLength += String.valueOf(element).length();
}
StringBuilder sb = new StringBuilder(totalLength);