Skip to content

Commit 94f5d72

Browse files
committed
HV-1955 Use String#isBlank instead of trim in the NotBlankValidator
1 parent 7fae7ac commit 94f5d72

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

engine/src/main/java/org/hibernate/validator/internal/constraintvalidators/bv/NotBlankValidator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@
99
import jakarta.validation.constraints.NotBlank;
1010

1111
/**
12-
* Check that a character sequence is not {@code null} nor empty after removing any leading or trailing whitespace.
12+
* Check that a character sequence is not {@code null} nor {@link String#isBlank() blank}.
1313
*
1414
* @author Guillaume Smet
1515
*/
1616
public class NotBlankValidator implements ConstraintValidator<NotBlank, CharSequence> {
1717

1818
/**
19-
* Checks that the character sequence is not {@code null} nor empty after removing any leading or trailing
20-
* whitespace.
19+
* Checks that the character sequence is not {@code null} nor {@link String#isBlank() blank}.
2120
*
2221
* @param charSequence the character sequence to validate
2322
* @param constraintValidatorContext context in which the constraint is evaluated
24-
* @return returns {@code true} if the string is not {@code null} and the length of the trimmed
25-
* {@code charSequence} is strictly superior to 0, {@code false} otherwise
23+
* @return returns {@code true} if the string is not {@code null} and
24+
* the call to {@link String#isBlank() charSequence.isBlank()} returns {@code false}, {@code false} otherwise
25+
* @see String#isBlank()
2626
*/
2727
@Override
2828
public boolean isValid(CharSequence charSequence, ConstraintValidatorContext constraintValidatorContext) {
2929
if ( charSequence == null ) {
3030
return false;
3131
}
3232

33-
return charSequence.toString().trim().length() > 0;
33+
return !charSequence.toString().isBlank();
3434
}
3535
}

0 commit comments

Comments
 (0)