HBASE-6049 Serializing 'List' containing null elements will cause NullPointerException in HbaseObjectWritable.writeObject()
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1344363 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
20bd3f02d0
commit
2bbc95823c
@ -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);
|
||||
|
@ -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<String> listWithNulls = new ArrayList<String>();
|
||||
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<String> arr = new ArrayList<String>();
|
||||
arr.add("hello");
|
||||
|
Loading…
x
Reference in New Issue
Block a user