diff --git a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java index 06dd448d76c6..8fc02a1a2b98 100644 --- a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java @@ -191,7 +191,7 @@ public static Object unwrapOptional(@Nullable Object obj) { * @return whether the element has been found in the given array */ public static boolean containsElement(@Nullable Object[] array, Object element) { - if (array == null) { + if (isEmpty(array)) { return false; } for (Object arrayEle : array) { 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 718f276794cc..b3e99ea30de8 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -166,16 +166,11 @@ public static boolean hasLength(@Nullable String str) { */ @Contract("null -> false") public static boolean hasText(@Nullable CharSequence str) { - if (str == null) { - return false; - } - - int strLen = str.length(); - if (strLen == 0) { + if (isEmpty(str)) { return false; } - for (int i = 0; i < strLen; i++) { + for (int i = 0; i < str.length(); i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; }