diff --git a/spring-core/src/main/java/org/springframework/util/StringUtils.java b/spring-core/src/main/java/org/springframework/util/StringUtils.java index 6abec41ee2..14938f2eaf 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -983,12 +983,12 @@ public abstract class StringUtils { /** * Trim the elements of the given {@code String} array, * calling {@code String.trim()} on each of them. - * @param array the original {@code String} array + * @param array the original {@code String} array (potentially {@code null} or empty) * @return the resulting array (of the same size) with trimmed elements */ - public static String[] trimArrayElements(@Nullable String[] array) { + public static String[] trimArrayElements(String[] array) { if (ObjectUtils.isEmpty(array)) { - return new String[0]; + return array; } String[] result = new String[array.length]; @@ -1002,7 +1002,7 @@ public abstract class StringUtils { /** * Remove duplicate strings from the given array. *
As of 4.2, it preserves the original order, as it uses a {@link LinkedHashSet}.
- * @param array the {@code String} array
+ * @param array the {@code String} array (potentially empty)
* @return an array without duplicates, in natural sort order
*/
public static String[] removeDuplicateStrings(String[] array) {
@@ -1010,18 +1010,15 @@ public abstract class StringUtils {
return array;
}
- Set Note that this will suppress duplicates, and as of 4.2, the elements in
* the returned set will preserve the original order in a {@link LinkedHashSet}.
- * @param str the input {@code String}
+ * @param str the input {@code String} (potentially {@code null} or empty)
* @return a set of {@code String} entries in the list
* @see #removeDuplicateStrings(String[])
*/
public static Set Useful for {@code toString()} implementations.
- * @param coll the {@code Collection} to convert
+ * @param coll the {@code Collection} to convert (potentially {@code null} or empty)
* @param delim the delimiter to use (typically a ",")
* @param prefix the {@code String} to start each element with
* @param suffix the {@code String} to end each element with
@@ -1272,7 +1265,7 @@ public abstract class StringUtils {
/**
* Convert a {@code Collection} into a delimited {@code String} (e.g. CSV).
* Useful for {@code toString()} implementations.
- * @param coll the {@code Collection} to convert
+ * @param coll the {@code Collection} to convert (potentially {@code null} or empty)
* @param delim the delimiter to use (typically a ",")
* @return the delimited {@code String}
*/
@@ -1283,17 +1276,17 @@ public abstract class StringUtils {
/**
* Convert a {@code Collection} into a delimited {@code String} (e.g., CSV).
* Useful for {@code toString()} implementations.
- * @param coll the {@code Collection} to convert
+ * @param coll the {@code Collection} to convert (potentially {@code null} or empty)
* @return the delimited {@code String}
*/
- public static String collectionToCommaDelimitedString(Collection> coll) {
+ public static String collectionToCommaDelimitedString(@Nullable Collection> coll) {
return collectionToDelimitedString(coll, ",");
}
/**
* Convert a {@code String} array into a delimited {@code String} (e.g. CSV).
* Useful for {@code toString()} implementations.
- * @param arr the array to display
+ * @param arr the array to display (potentially {@code null} or empty)
* @param delim the delimiter to use (typically a ",")
* @return the delimited {@code String}
*/
@@ -1319,7 +1312,7 @@ public abstract class StringUtils {
* Convert a {@code String} array into a comma delimited {@code String}
* (i.e., CSV).
* Useful for {@code toString()} implementations.
- * @param arr the array to display
+ * @param arr the array to display (potentially {@code null} or empty)
* @return the delimited {@code String}
*/
public static String arrayToCommaDelimitedString(@Nullable Object[] arr) {