Skip to content

Commit 2d0ab47

Browse files
committed
Consistent hasText checks for CharSequence vs String
Directly inlined hasLength implementations for proper nullability detection in IntelliJ, assuming a hasText checked value is never null afterwards. Since the JVM is going to do this at runtime anyway, this is effectively equivalent but more indicative for source code introspection algorithms. Issue: SPR-15540
1 parent 9efdadc commit 2d0ab47

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

spring-core/src/main/java/org/springframework/util/StringUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static boolean hasLength(@Nullable String str) {
139139
* @see Character#isWhitespace
140140
*/
141141
public static boolean hasText(@Nullable CharSequence str) {
142-
return (hasLength(str) && containsText(str));
142+
return (str != null && str.length() > 0 && containsText(str));
143143
}
144144

145145
/**
@@ -153,7 +153,7 @@ public static boolean hasText(@Nullable CharSequence str) {
153153
* @see #hasText(CharSequence)
154154
*/
155155
public static boolean hasText(@Nullable String str) {
156-
return (hasLength(str) && containsText(str));
156+
return (str != null && !str.isEmpty() && containsText(str));
157157
}
158158

159159
private static boolean containsText(CharSequence str) {

0 commit comments

Comments
 (0)