Browse Source

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
pull/1576/head
Juergen Hoeller 8 years ago
parent
commit
2d0ab4740c
  1. 4
      spring-core/src/main/java/org/springframework/util/StringUtils.java

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

@ -139,7 +139,7 @@ public abstract class StringUtils { @@ -139,7 +139,7 @@ public abstract class StringUtils {
* @see Character#isWhitespace
*/
public static boolean hasText(@Nullable CharSequence str) {
return (hasLength(str) && containsText(str));
return (str != null && str.length() > 0 && containsText(str));
}
/**
@ -153,7 +153,7 @@ public abstract class StringUtils { @@ -153,7 +153,7 @@ public abstract class StringUtils {
* @see #hasText(CharSequence)
*/
public static boolean hasText(@Nullable String str) {
return (hasLength(str) && containsText(str));
return (str != null && !str.isEmpty() && containsText(str));
}
private static boolean containsText(CharSequence str) {

Loading…
Cancel
Save