Browse Source

HDFS-10809. getNumEncryptionZones causes NPE in branch-2.7. Contributed by Vinitha Reddy Gankidi.

Zhe Zhang 8 years ago
parent
commit
85a067fd6b

+ 2 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java

@@ -390,7 +390,8 @@ public class EncryptionZoneManager {
    * @return number of encryption zones.
    * @return number of encryption zones.
    */
    */
   public int getNumEncryptionZones() {
   public int getNumEncryptionZones() {
-    return encryptionZones.size();
+    return hasCreatedEncryptionZone() ?
+        encryptionZones.size() : 0;
   }
   }
 
 
   /**
   /**

+ 3 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java

@@ -217,7 +217,9 @@ public class TestEncryptionZones {
   public void testBasicOperations() throws Exception {
   public void testBasicOperations() throws Exception {
 
 
     int numZones = 0;
     int numZones = 0;
-
+    /* Number of EZs should be 0 if no EZ is created */
+    assertEquals("Unexpected number of encryption zones!", numZones,
+        cluster.getNamesystem().getNumEncryptionZones());
     /* Test failure of create EZ on a directory that doesn't exist. */
     /* Test failure of create EZ on a directory that doesn't exist. */
     final Path zoneParent = new Path("/zones");
     final Path zoneParent = new Path("/zones");
     final Path zone1 = new Path(zoneParent, "zone1");
     final Path zone1 = new Path(zoneParent, "zone1");