Reviewers: skybrian,
Description:
EditorDriver#setConstraintViolations used to thrown NPE if arg was null.
Issue 6578
Please review this at https://gwt-code-reviews.appspot.com/1826803/
Affected files:
M user/src/com/google/gwt/editor/client/impl/SimpleViolation.java
M
user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
M user/test/com/google/gwt/editor/client/EditorErrorTest.java
Index: user/src/com/google/gwt/editor/client/impl/SimpleViolation.java
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
ab4e9eaec1dbf30e08b8e81ff1fbc3fbb0665de4..c030aeb57670dc5400fb608bd5404f927148d081
100644
--- a/user/src/com/google/gwt/editor/client/impl/SimpleViolation.java
+++ b/user/src/com/google/gwt/editor/client/impl/SimpleViolation.java
@@ -100,7 +100,7 @@ public abstract class SimpleViolation {
public static Iterable<SimpleViolation> iterableFromConstrantViolations(
Iterable<ConstraintViolation<?>> violations) {
- return new ConstraintViolationIterable(violations);
+ return violations == null ? null : new
ConstraintViolationIterable(violations);
}
/**
@@ -109,6 +109,10 @@ public abstract class SimpleViolation {
*/
public static void pushViolations(Iterable<SimpleViolation> violations,
EditorDriver<?> driver, KeyMethod keyMethod) {
+ if (violations == null) {
+ return;
+ }
+
DelegateMap delegateMap = DelegateMap.of(driver, keyMethod);
// For each violation
Index:
user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
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
fa7aa35e7956504ad9613408c4fb4b7fc36f87b1..330ec434ab571df1abee4ec5b3ae0bf19b4f947f
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 @@ public abstract class
AbstractRequestFactoryEditorDriver<R, E extends Editor<R>>
@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() {
Index: user/test/com/google/gwt/editor/client/EditorErrorTest.java
diff --git a/user/test/com/google/gwt/editor/client/EditorErrorTest.java
b/user/test/com/google/gwt/editor/client/EditorErrorTest.java
index
8900d5f9c236c38d1f08bb5a1bb7333a2c3c25c5..755ebef191ad74660cd706f321eda01b19395f4b
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
com.google.gwt.validation.client.impl.ConstraintViolationImpl;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -193,6 +194,22 @@ public class EditorErrorTest extends GWTTestCase {
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() {
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors