I am puzzled by the javax.validation API. I am writing a simple test to understand it:
Sample sample = new Sample();
Set<ConstraintViolation<Sample>> violations = validator.validate(sample);
if (!violations.isEmpty()) {
// Eclipse refuses to let me use my violations variable
throw new ConstraintViolationException(violations);
}
How should I declare the set of violations so I can use it in my exception constructor?
You can work around this like so:
throw new ConstraintViolationException(
new HashSet<ConstraintViolation<?>>(violations));
You may be interested in tracking BVAL-198 which addresses this issue.