If some unrecoverable failure happens during validation, a ValidationException is raised.

[JSR 303 TCK Result] 66 of 257 (25.68%) Pass with 25 Failures and 3 Errors.

Review at http://gwt-code-reviews.appspot.com/1295803

Review by: rchandia@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9615 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java b/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
index 6432bb4..c839b5e 100644
--- a/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
+++ b/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
@@ -230,9 +230,10 @@
 
   @Override
   protected void compose(ClassSourceFileComposerFactory composerFactory) {
-    addImports(composerFactory, GWT.class, GwtBeanDescriptor.class,
-        GwtValidationContext.class, Set.class, HashSet.class,
-        ConstraintViolation.class, Annotation.class);
+    addImports(composerFactory, Annotation.class, ConstraintViolation.class,
+        GWT.class, GwtBeanDescriptor.class, GwtValidationContext.class,
+        HashSet.class, IllegalArgumentException.class, Set.class,
+        ValidationException.class);
     composerFactory.setSuperclass(AbstractGwtSpecificValidator.class.getCanonicalName()
         + "<" + beanType.getQualifiedSourceName() + ">");
     composerFactory.addImplementedInterface(validatorType.getName());
@@ -537,6 +538,36 @@
     sw.outdent();
   }
 
+  private void writeCatchUnexpectedException(SourceWriter sw, String message) {
+    // } catch (IllegalArgumentException e) {
+    sw.outdent();
+    sw.println("} catch (IllegalArgumentException e) {");
+    sw.indent();
+
+    // throw e;
+    sw.println("throw e;");
+
+    // } catch (ValidationException e) {
+    sw.outdent();
+    sw.println("} catch (ValidationException e) {");
+    sw.indent();
+
+    // throw e;
+    sw.println("throw e;");
+
+    // } catch (Exception e) {
+    sw.outdent();
+    sw.println("} catch (Exception e) {");
+    sw.indent();
+
+    // throw new ValidationException("my message", e);
+    sw.println("throw new ValidationException(" + message + ", e);");
+
+    // }
+    sw.outdent();
+    sw.println("}");
+  }
+
   private void writeConstraintDescriptor(SourceWriter sw,
       ConstraintDescriptor<? extends Annotation> constraint,
       String constraintDescripotorVar) throws UnableToCompleteException {
@@ -893,6 +924,10 @@
     sw.println("Class<?>... groups) {");
     sw.outdent();
 
+    // try {
+    sw.println("try {");
+    sw.indent();
+
     writeNewViolations(sw);
 
     if (beanHelper.getBeanDescriptor().isBeanConstrained()) {
@@ -956,6 +991,10 @@
     // return violations;
     sw.println("return violations;");
 
+    writeCatchUnexpectedException(
+        sw,
+        "\"Error validating " + beanHelper.getTypeCanonicalName() + "\"");
+
     sw.outdent();
     sw.println("}");
   }
@@ -1173,15 +1212,19 @@
     sw.println("public <T> Set<ConstraintViolation<T>> validateProperty(");
 
     // GwtValidationContext<T> context, BeanType object, String propertyName,
-    // Class<?>... groups) {
+    // Class<?>... groups) throws ValidationException {
     sw.indent();
     sw.indent();
     sw.println("GwtValidationContext<T> context,");
     sw.println(beanHelper.getTypeCanonicalName() + " object,");
     sw.println("String propertyName,");
-    sw.println("Class<?>... groups) {");
+    sw.println("Class<?>... groups) throws ValidationException {");
     sw.outdent();
 
+    // try {
+    sw.println("try {");
+    sw.indent();
+
     writeNewViolations(sw);
 
     for (PropertyDescriptor property : beanHelper.getBeanDescriptor().getConstrainedProperties()) {
@@ -1207,6 +1250,12 @@
     // return violations;
     sw.println("return violations;");
 
+    writeCatchUnexpectedException(
+        sw,
+        "\"Error validating \" + propertyName + \" of "
+        + beanHelper.getTypeCanonicalName() + "\"");
+
+    // }
     sw.outdent();
     sw.println("}");
   }
@@ -1257,8 +1306,7 @@
 
       // throw new ValidationException(value.getClass +
       // " is not a valid type for " + propertyName);
-      sw.print("throw new ");
-      sw.print(ValidationException.class.getCanonicalName());
+      sw.print("throw new ValidationException");
       sw.println("(value.getClass() +\" is not a valid type for \"+ propertyName);");
 
       // }
@@ -1365,6 +1413,10 @@
     sw.println("Class<?>... groups) {");
     sw.outdent();
 
+    // try {
+    sw.println("try {");
+    sw.indent();
+
     writeNewViolations(sw);
 
     for (PropertyDescriptor property :
@@ -1393,6 +1445,11 @@
     // return violations;
     sw.println("return violations;");
 
+    writeCatchUnexpectedException(
+        sw,
+        "\"Error validating \" + propertyName + \" of "
+            + beanHelper.getTypeCanonicalName() + "\"");
+
     sw.outdent();
     sw.println("}");
   }
diff --git a/user/test/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyGwtTest.java b/user/test/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyGwtTest.java
index d24b44b..5c72d4e 100644
--- a/user/test/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyGwtTest.java
+++ b/user/test/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyGwtTest.java
@@ -34,7 +34,6 @@
     delegate.testPassingNullAsGroup();
   }
 
-  @Failing(issue = 5804)
   public void testUnexpectedExceptionsInValidatePropertyGetWrappedInValidationExceptions() {
     // Wrap the test to catch the @Test expected exception.
     try {