You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@crunch.apache.org by jw...@apache.org on 2012/10/29 22:38:40 UTC

git commit: CRUNCH-103: Add null checking to the CollectionDeepCopier

Updated Branches:
  refs/heads/master 2af9cbae4 -> a8847de58


CRUNCH-103: Add null checking to the CollectionDeepCopier


Project: http://git-wip-us.apache.org/repos/asf/incubator-crunch/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-crunch/commit/a8847de5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-crunch/tree/a8847de5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-crunch/diff/a8847de5

Branch: refs/heads/master
Commit: a8847de5851b2886852a6e8c6afb6f173ae4f921
Parents: 2af9cba
Author: Josh Wills <jw...@apache.org>
Authored: Mon Oct 29 14:21:36 2012 -0700
Committer: Josh Wills <jw...@apache.org>
Committed: Mon Oct 29 14:21:36 2012 -0700

----------------------------------------------------------------------
 .../apache/crunch/types/CollectionDeepCopier.java  |    3 +++
 .../crunch/types/CollectionDeepCopierTest.java     |    9 +++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/a8847de5/crunch/src/main/java/org/apache/crunch/types/CollectionDeepCopier.java
----------------------------------------------------------------------
diff --git a/crunch/src/main/java/org/apache/crunch/types/CollectionDeepCopier.java b/crunch/src/main/java/org/apache/crunch/types/CollectionDeepCopier.java
index db62e85..151ab82 100644
--- a/crunch/src/main/java/org/apache/crunch/types/CollectionDeepCopier.java
+++ b/crunch/src/main/java/org/apache/crunch/types/CollectionDeepCopier.java
@@ -44,6 +44,9 @@ public class CollectionDeepCopier<T> implements DeepCopier<Collection<T>> {
 
   @Override
   public Collection<T> deepCopy(Collection<T> source) {
+    if (source == null) {
+      return null;
+    }
     List<T> copiedCollection = Lists.newArrayListWithCapacity(source.size());
     for (T value : source) {
       copiedCollection.add(elementType.getDetachedValue(value));

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/a8847de5/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java b/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java
index e28d094..bd7fcd7 100644
--- a/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java
@@ -19,6 +19,7 @@ package org.apache.crunch.types;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
 
 import java.util.Collection;
 
@@ -49,4 +50,12 @@ public class CollectionDeepCopierTest {
     assertNotSame(personCollection.iterator().next(), deepCopyCollection.iterator().next());
   }
 
+  @Test
+  public void testNullDeepCopy() {
+    CollectionDeepCopier<Person> collectionDeepCopier = new CollectionDeepCopier<Person>(
+        Avros.records(Person.class));
+    collectionDeepCopier.initialize(new Configuration());
+    Collection<Person> nullCollection = null;
+    assertNull(collectionDeepCopier.deepCopy(nullCollection));
+  }
 }