In this case @NotBlank constraint handles null as a value but @Length constraint doesn't so if the order of their execution is random sometimes you can get the NullPointerException
There should be no NullPointerException one way of the other. As you say, constraint validators might treat null values differently, but they should never throw an exception. Most validators treat a null value as valid, and rely on constraint composition and for example the existence of an additional @NotNull. @NotBlank is a bit different, since it explicitly checks for the null value: "Validate that the annotated string is not null or empty." Do you have a case where a combination of built-in constraints throw a NullPointerException? I would consider this a bug.
This can be fixed simpler than HV-706, generally speaking Option1 is not going to resolve this issue because of the eliminated groups parameter of the composing annotation.
Personally I prefer option 2
I suggest to extend the @ConstraintComposition with an order parameter, so it could be:
I would prefer if a solution for HV-706 also applies for constraint composition, instead of introducing yet another annotation/concept. |