The documentation for @NotBlank says “The annotated element must not be null and must contain at least one non-whitespace character. Accepts CharSequence.” and refers to Character.isWhitespace(char). But NotBlankValidator uses trim() whose definition of a “space character” is different from Character.isWhitespace(char). String.isBlank() (introduced in Java 11) would be a better implementation choice. If pre-Java 11 compatibility is required, Character.isWhitespace(char) could be be used. |