ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ag...@apache.org
Subject ignite git commit: ignite-5839 Fix BinaryObject builder reuse issue.
Date Mon, 18 Sep 2017 17:52:59 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 8a75a98b2 -> 8d0aab7f4


ignite-5839 Fix BinaryObject builder reuse issue.

Signed-off-by: Andrey Gura <agura@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8d0aab7f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8d0aab7f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8d0aab7f

Branch: refs/heads/master
Commit: 8d0aab7f4912c828e8d105e8cda1f5c6842244c7
Parents: 8a75a98
Author: Andrey V. Mashenkov <andrey.mashenkov@gmail.com>
Authored: Mon Sep 18 20:47:47 2017 +0300
Committer: Andrey Gura <agura@apache.org>
Committed: Mon Sep 18 20:47:47 2017 +0300

----------------------------------------------------------------------
 .../binary/builder/BinaryObjectBuilderImpl.java | 17 ++++++-------
 .../BinaryObjectBuilderAdditionalSelfTest.java  | 26 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8d0aab7f/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
index 9108f89..b9eb3e5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@ -549,16 +549,18 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder
{
 
     /** {@inheritDoc} */
     @Override public BinaryObjectBuilder setField(String name, Object val0) {
-        Object val = val0 == null ? new BinaryValueWithType(BinaryUtils.typeByClass(Object.class),
null) : val0;
+        Object val = assignedValues().get(name);
 
-        Object oldVal = assignedValues().put(name, val);
-
-        if (oldVal instanceof BinaryValueWithType && val0 != null) {
-            ((BinaryValueWithType)oldVal).value(val);
+        if (val instanceof BinaryValueWithType)
+            ((BinaryValueWithType)val).value(val0);
+        else {
+            Class valCls = (val == null) ? Object.class : val.getClass();
 
-            assignedValues().put(name, oldVal);
+            val = val0 == null ? new BinaryValueWithType(BinaryUtils.typeByClass(valCls),
null) : val0;
         }
 
+        assignedValues().put(name, val);
+
         return this;
     }
 
@@ -580,9 +582,6 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
 
     /** {@inheritDoc} */
     @Override public BinaryObjectBuilder setField(String name, @Nullable BinaryObjectBuilder
builder) {
-        if (builder == null)
-            return setField(name, null, Object.class);
-        else
             return setField(name, (Object)builder);
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/8d0aab7f/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
index 4ac2758..dd748a8 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
@@ -1617,6 +1617,32 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
     }
 
     /**
+     * @throws Exception If fails
+     */
+    public void testBuilderReusage() throws Exception {
+        // Check: rewrite null field value.
+        BinaryObjectBuilder builder = newWrapper("SimpleCls1");
+
+        builder.setField("f1", null, Object.class);
+        assertNull(builder.build().field("f1"));
+
+        builder.setField("f1", "val1");
+        assertEquals("val1", builder.build().field("f1"));
+
+        // Check: rewrite non-null field value to null and back.
+        builder = newWrapper("SimpleCls2");
+
+        builder.setField("f1", "val1", String.class);
+        assertEquals("val1", builder.build().field("f1"));
+
+        builder.setField("f1", null);
+        assertNull(builder.build().field("f1"));
+
+        builder.setField("f1", "val2");
+        assertEquals("val2", builder.build().field("f1"));
+    }
+
+    /**
      *
      */
     private static class TestObjectExternalizable implements Externalizable {


Mime
View raw message