79393080

Date: 2025-01-28 08:09:17
Score: 2
Natty:
Report link

This is actually a common issue when working with validation annotations in Spring Boot. The problem here is that both @NotBlank and @Size(min = 2) are getting triggered, even when you send an empty string. Here’s why:

@NotBlank checks if the string is not empty (or just whitespace). @Size(min = 2) checks the length of the string to make sure it has at least 2 characters. When you send an empty string, @NotBlank will fail first because the field is empty. But Spring’s validation process doesn’t stop there — it will still evaluate other constraints, like @Size(min = 2), and give you both error messages.

In terms of validation flow, Spring doesn’t guarantee that @NotBlank will always run first, and both annotations are usually evaluated together. So in this case, you’re seeing both errors even though you expected @NotBlank to take precedence.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @NotBlank
  • User mentioned (0): @NotBlank
  • User mentioned (0): @NotBlank
  • User mentioned (0): @NotBlank
  • User mentioned (0): @NotBlank
  • Low reputation (1):
Posted by: Vedant Kakade