HADOOP-14459. SerializationFactory shouldn't throw a NullPointerException if the serializations list is not defined

(Contributed by Nandor Kollar via Daniel Templeton)
This commit is contained in:
Daniel Templeton 2017-10-04 15:04:02 +02:00
parent acf5b880d8
commit 20e9ce3ab3
2 changed files with 19 additions and 12 deletions

View File

@ -55,18 +55,12 @@ public class SerializationFactory extends Configured {
*/
public SerializationFactory(Configuration conf) {
super(conf);
if (conf.get(CommonConfigurationKeys.IO_SERIALIZATIONS_KEY).equals("")) {
LOG.warn("Serialization for various data types may not be available. Please configure "
+ CommonConfigurationKeys.IO_SERIALIZATIONS_KEY
+ " properly to have serialization support (it is currently not set).");
} else {
for (String serializerName : conf.getTrimmedStrings(
CommonConfigurationKeys.IO_SERIALIZATIONS_KEY, new String[] {
WritableSerialization.class.getName(),
AvroSpecificSerialization.class.getName(),
AvroReflectSerialization.class.getName() })) {
add(conf, serializerName);
}
for (String serializerName : conf.getTrimmedStrings(
CommonConfigurationKeys.IO_SERIALIZATIONS_KEY,
new String[]{WritableSerialization.class.getName(),
AvroSpecificSerialization.class.getName(),
AvroReflectSerialization.class.getName()})) {
add(conf, serializerName);
}
}

View File

@ -51,6 +51,19 @@ public void testSerializationKeyIsEmpty() {
SerializationFactory factory = new SerializationFactory(conf);
}
/**
* Test the case when {@code IO_SERIALIZATIONS_KEY}
* is not set at all, because something unset this key.
* This shouldn't result in any error, the defaults present
* in construction should be used in this case.
*/
@Test
public void testSerializationKeyIsUnset() {
Configuration conf = new Configuration();
conf.unset(CommonConfigurationKeys.IO_SERIALIZATIONS_KEY);
SerializationFactory factory = new SerializationFactory(conf);
}
@Test
public void testSerializationKeyIsInvalid() {
Configuration conf = new Configuration();