Fix EditorDriver.setConstraintViolations to not throw NullPointerException when
its argument is null.

Contributed by tbroyer
Fixes issue 6578
Review at https://gwt-code-reviews.appspot.com/1826803/

Review by: cromwellian@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11261 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/editor/client/impl/BaseEditorDriver.java b/user/src/com/google/gwt/editor/client/impl/BaseEditorDriver.java
index 7c4dc5f..84d1097 100644
--- a/user/src/com/google/gwt/editor/client/impl/BaseEditorDriver.java
+++ b/user/src/com/google/gwt/editor/client/impl/BaseEditorDriver.java
@@ -64,7 +64,8 @@
   }
 
   public boolean setConstraintViolations(final Iterable<ConstraintViolation<?>> violations) {
-    return doSetViolations(SimpleViolation.iterableFromConstrantViolations(violations));
+    return doSetViolations(violations == null ? null : SimpleViolation
+        .iterableFromConstrantViolations(violations));
   }
 
   @Override
diff --git a/user/src/com/google/gwt/editor/client/impl/SimpleViolation.java b/user/src/com/google/gwt/editor/client/impl/SimpleViolation.java
index ab4e9ea..803980f 100644
--- a/user/src/com/google/gwt/editor/client/impl/SimpleViolation.java
+++ b/user/src/com/google/gwt/editor/client/impl/SimpleViolation.java
@@ -109,6 +109,10 @@
    */
   public static void pushViolations(Iterable<SimpleViolation> violations,
       EditorDriver<?> driver, KeyMethod keyMethod) {
+    if (violations == null) {
+      return;
+    }
+
     DelegateMap delegateMap = DelegateMap.of(driver, keyMethod);
 
     // For each violation
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
index fa7aa35..330ec43 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
@@ -196,7 +196,7 @@
   @SuppressWarnings("deprecation")
   public boolean setViolations(
       Iterable<com.google.web.bindery.requestfactory.shared.Violation> violations) {
-    return doSetViolations(new ViolationIterable(violations));
+    return doSetViolations(violations == null ? null : new ViolationIterable(violations));
   }
 
   protected void checkSaveRequest() {
diff --git a/user/test/com/google/gwt/editor/client/EditorErrorTest.java b/user/test/com/google/gwt/editor/client/EditorErrorTest.java
index 8900d5f..755ebef 100644
--- a/user/test/com/google/gwt/editor/client/EditorErrorTest.java
+++ b/user/test/com/google/gwt/editor/client/EditorErrorTest.java
@@ -23,6 +23,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -193,6 +194,22 @@
     driver.edit(p);
     driver.flush();
     assertEquals(0, editor.errors.size());
+    assertFalse(driver.hasErrors());
+    assertNotNull(driver.getErrors());
+    assertEquals(0, driver.getErrors().size());
+
+    assertFalse(driver.setConstraintViolations(Collections.<ConstraintViolation<?>>emptyList()));
+    assertEquals(0, editor.errors.size());
+    assertFalse(driver.hasErrors());
+    assertNotNull(driver.getErrors());
+    assertEquals(0, driver.getErrors().size());
+
+    // Test no NPE is thrown; see issue 6578
+    assertFalse(driver.setConstraintViolations(null));
+    assertEquals(0, editor.errors.size());
+    assertFalse(driver.hasErrors());
+    assertNotNull(driver.getErrors());
+    assertEquals(0, driver.getErrors().size());
   }
 
   public void testSimpleError() {