diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java index 35b2c8b01cd..e19af32ba64 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java @@ -477,8 +477,9 @@ public class HbaseObjectWritable implements Writable, WritableWithSize, Configur int length = list.size(); out.writeInt(length); for (int i = 0; i < length; i++) { - writeObject(out, list.get(i), - list.get(i).getClass(), conf); + Object elem = list.get(i); + writeObject(out, elem, + elem == null ? Writable.class : elem.getClass(), conf); } } else if (declClass == String.class) { // String Text.writeString(out, (String)instanceObj); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java index d8e3ee1709b..2e666668d63 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java @@ -198,6 +198,14 @@ public class TestHbaseObjectWritable extends TestCase { obj = doType(conf, list, List.class); assertTrue(obj instanceof List); Assert.assertArrayEquals(list.toArray(), ((List)obj).toArray() ); + //List.class with null values + List listWithNulls = new ArrayList(); + listWithNulls.add("hello"); + listWithNulls.add("world"); + listWithNulls.add(null); + obj = doType(conf, listWithNulls, List.class); + assertTrue(obj instanceof List); + Assert.assertArrayEquals(listWithNulls.toArray(), ((List)obj).toArray() ); //ArrayList.class ArrayList arr = new ArrayList(); arr.add("hello");