Reviewers: rjrjr,

Description:
Fix NPE in AbstractRequestContext with newly-created items.
Add a test.
Patch by: bobv
Review by: rjrjr


Please review this at http://gwt-code-reviews.appspot.com/938802/show

Affected files:
M user/src/com/google/gwt/requestfactory/client/impl/AbstractRequestContext.java
  M user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java


Index: user/src/com/google/gwt/requestfactory/client/impl/AbstractRequestContext.java
===================================================================
--- user/src/com/google/gwt/requestfactory/client/impl/AbstractRequestContext.java (revision 8922) +++ user/src/com/google/gwt/requestfactory/client/impl/AbstractRequestContext.java (working copy)
@@ -142,13 +142,18 @@
     /*
      * NB: Don't use the presence of ephemeral objects for this test.
      *
-     * Diffing the objects until one is found to be different. It's not
-     * just a simple flag-check because of the possibility of "unmaking" a
-     * change, per the JavaDoc.
+ * Diffing the objects until one is found to be different. It's not just a + * simple flag-check because of the possibility of "unmaking" a change, per
+     * the JavaDoc.
      */
     for (EntityProxy edited : seenProxies.values()) {
       AutoBean<EntityProxy> bean = AutoBeanUtils.getAutoBean(edited);
- AutoBean<EntityProxy> previous = AutoBeanUtils.getAutoBean((EntityProxy) bean.getTag(PARENT_OBJECT)); + AutoBean<?> previous = AutoBeanUtils.getAutoBean((EntityProxy) bean.getTag(PARENT_OBJECT));
+      if (previous == null) {
+        // Compare to empty object
+        previous = getRequestFactory().getAutoBeanFactory().create(
+            edited.stableId().getProxyClass());
+      }
       if (!AutoBeanUtils.diff(previous, bean).isEmpty()) {
         return true;
       }
Index: user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
===================================================================
--- user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java (revision 8922) +++ user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java (working copy)
@@ -219,6 +219,24 @@
         finishTestAndReset();
       }
     });
+  }
+
+  public void testChanged() {
+    // Nothing has happened
+    SimpleFooRequest context = simpleFooRequest();
+    assertFalse(context.isChanged());
+
+    // Creates don't cause a change
+    SimpleFooProxy foo = context.create(SimpleFooProxy.class);
+    assertFalse(context.isChanged());
+
+    // Change
+    foo.setCharField('c');
+    assertTrue(context.isChanged());
+
+    // Undo the change
+    foo.setCharField(null);
+    assertFalse(context.isChanged());
   }

   public void testClassToken() {


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to