ayushtkn commented on code in PR #3342:
URL: https://github.com/apache/ozone/pull/3342#discussion_r862453964


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetUtils.java:
##########
@@ -149,4 +149,28 @@ public static List<Node> getAncestorList(NetworkTopology 
topology,
     }
     return ancestorList;
   }
+
+  /**
+   * Ensure {@link NetConstants#PATH_SEPARATOR_STR} is added to the suffix of
+   * the path.
+   * @param path path to add suffix
+   * @return the normalised path
+   * If <i>path</i>is empty, then {@link NetConstants#ROOT} is returned
+   */
+  public static String addSuffix(String path) {
+    if (path == null) {
+      return null;
+    }
+
+    int len = path.length();
+    if (len == 0) {
+      return NetConstants.PATH_SEPARATOR_STR;

Review Comment:
   In the javadoc you said `` If <i>path</i>is empty, then {@link 
NetConstants#ROOT} is returned`` but here you are returning ``return 
NetConstants.PATH_SEPARATOR_STR`` both have different values.



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetUtils.java:
##########
@@ -149,4 +149,28 @@ public static List<Node> getAncestorList(NetworkTopology 
topology,
     }
     return ancestorList;
   }
+
+  /**
+   * Ensure {@link NetConstants#PATH_SEPARATOR_STR} is added to the suffix of
+   * the path.
+   * @param path path to add suffix
+   * @return the normalised path
+   * If <i>path</i>is empty, then {@link NetConstants#ROOT} is returned
+   */
+  public static String addSuffix(String path) {
+    if (path == null) {
+      return null;
+    }
+
+    int len = path.length();
+    if (len == 0) {
+      return NetConstants.PATH_SEPARATOR_STR;
+    }
+
+    if (path.charAt(len - 1) != NetConstants.PATH_SEPARATOR) {
+      return path + NetConstants.PATH_SEPARATOR_STR;
+    }
+
+    return path;

Review Comment:
   ```suggestion
       if (!path.endsWith(NetConstants.PATH_SEPARATOR_STR)) {
         return path + NetConstants.PATH_SEPARATOR_STR;
       }
   ```
   Does this do the same thing?



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetUtils.java:
##########
@@ -149,4 +149,28 @@ public static List<Node> getAncestorList(NetworkTopology 
topology,
     }
     return ancestorList;
   }
+
+  /**
+   * Ensure {@link NetConstants#PATH_SEPARATOR_STR} is added to the suffix of
+   * the path.
+   * @param path path to add suffix
+   * @return the normalised path
+   * If <i>path</i>is empty, then {@link NetConstants#ROOT} is returned
+   */
+  public static String addSuffix(String path) {
+    if (path == null) {
+      return null;
+    }

Review Comment:
   Why are you returning ``null`` here? Won't this lead to NPE in the 
isDecendent(String ..) & isAncesstor(String ..) methods. 
   For the same methods with argument as Node, if node is ``null``, you return 
false, but for the methods with argument as string you would return NPE, if the 
path is ``null``
   
   Just FYI. In normalize method, it returns root in case of ``null``
   
   ```
     public static String normalize(String path) {
       if (path == null) {
         return NetConstants.ROOT;
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to