Fix unsafe use and copy data to Set<ConstraintViolation<?>>

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17534 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2009-09-23 16:25:07 +00:00
parent 8cc9e9d5fd
commit 8eeaaeb286
1 changed files with 8 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package org.hibernate.cfg.beanvalidation;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
@ -67,15 +68,16 @@ public class BeanValidationEventListener implements
.getValidator(); .getValidator();
final Class<?>[] groups = groupsPerOperation.get( operation ); final Class<?>[] groups = groupsPerOperation.get( operation );
if ( groups.length > 0 ) { if ( groups.length > 0 ) {
final Set<ConstraintViolation<T>> constraintViolations = final Set<ConstraintViolation<T>> constraintViolations = validator.validate( object, groups );
validator.validate( object, groups );
//FIXME CV should no longer be generics
Object unsafeViolations = constraintViolations;
if (constraintViolations.size() > 0 ) { if (constraintViolations.size() > 0 ) {
//FIXME add Set<ConstraintViolation<?>> Set<ConstraintViolation<?>> propagatedViolations =
new HashSet<ConstraintViolation<?>>( constraintViolations.size() );
for ( ConstraintViolation<?> violation : constraintViolations) {
propagatedViolations.add(violation);
}
throw new ConstraintViolationException( throw new ConstraintViolationException(
"Invalid object at " + operation.getName() + " time for groups " + toString( groups ), "Invalid object at " + operation.getName() + " time for groups " + toString( groups ),
(Set<ConstraintViolation<?>>) unsafeViolations); propagatedViolations);
} }
} }
} }