While working with Hibernate Validator, I noticed that the @NotEmpty
and @NotNull
annotations produce duplicate messages in the InvalidValue
array returned by getInvalidValues(...)
.
If I specify a message like @NotEmpty(message = "My error message.")
, then I'll get one InvalidValue of "My error message." and a second of "may not be null or empty"
If i don't include a message (eg @NotEmpty
by itself), then I get two copies of the InvalidValue with a message field of "may not be null or empty".
Why does Hibernate Validator do this?? Shouldn't I get one message, either the value that I override using the parameter, or the default message, but not both??
For some more context:
I am extending ClassValidator<T>
with my own ClassValidator<MyClass>
implementation. I do so to add some custom validations which cannot be done by annotation. I need to see the run time value of more than one property of the class in order to determine the validation.
I get the validations when I call myClassValidator.getInvalidValues(), which I override. Inside my implementation of getInvalidValues()
I call super.getInvalidValues()
to create the initial error list, and then I add my custom errors to that list. In any case, the call to super.getInvalidValues()
contains the duplicate messages, one matching the message property passed into the annotation, and a second with the stock value of the annotation message.