diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ErasureCodingPolicy.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ErasureCodingPolicy.java index b63d2c06e01..368a2f265e6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ErasureCodingPolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ErasureCodingPolicy.java @@ -58,6 +58,8 @@ public final class ErasureCodingPolicy { } public static String composePolicyName(ECSchema schema, int cellSize) { + Preconditions.checkNotNull(schema); + Preconditions.checkArgument(cellSize > 0, "cellSize must be positive"); Preconditions.checkArgument(cellSize % 1024 == 0, "cellSize must be 1024 aligned"); return schema.getCodecName().toUpperCase() + "-" + diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java index 17fb01c8d2c..f1674af8b57 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java @@ -51,6 +51,28 @@ public class TestErasureCodingPolicy { } catch (IllegalArgumentException e) { GenericTestUtils.assertExceptionContains("cellSize", e); } + try { + new ErasureCodingPolicy(null, 1024, (byte) -1); + fail("Instantiated invalid ErasureCodingPolicy"); + } catch (NullPointerException e) { + } + try { + new ErasureCodingPolicy(SCHEMA_1, -1, (byte) -1); + fail("Instantiated invalid ErasureCodingPolicy"); + } catch (IllegalArgumentException e) { + GenericTestUtils.assertExceptionContains("cellSize", e); + } + try { + new ErasureCodingPolicy(null, 1024); + fail("Instantiated invalid ErasureCodingPolicy"); + } catch (NullPointerException e) { + } + try { + new ErasureCodingPolicy(SCHEMA_1, -1); + fail("Instantiated invalid ErasureCodingPolicy"); + } catch (IllegalArgumentException e) { + GenericTestUtils.assertExceptionContains("cellSize", e); + } } @Test