spring-framework / org.springframework.util / Assert / hasLength

hasLength

open static fun hasLength(@Nullable text: String, message: String): Unit

Assert that the given String is not empty; that is, it must not be null and not the empty String.

Assert.hasLength(name, "Name must not be empty");

Parameters

text - the String to check

message - the exception message to use if the assertion fails

Exceptions

IllegalArgumentException - if the text is empty

See Also
StringUtils#hasLength

open static fun hasLength(@Nullable text: String, messageSupplier: Supplier<String>): Unit

Assert that the given String is not empty; that is, it must not be null and not the empty String.

 Assert.hasLength(name, () -> "Name for account '" + account.getId() + "' must not be empty"); 

Parameters

text - the String to check

messageSupplier - a supplier for the exception message to use if the assertion fails

Exceptions

IllegalArgumentException - if the text is empty

See Also
StringUtils#hasLength

Since
5.0

open static fun hasLength(@Nullable text: String): Unit