You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "ayushtkn (via GitHub)" <gi...@apache.org> on 2023/05/15 06:01:26 UTC

[GitHub] [hadoop] ayushtkn commented on a diff in pull request #5653: HADOOP-18652. Path.suffix raises NullPointerException

ayushtkn commented on code in PR #5653:
URL: https://github.com/apache/hadoop/pull/5653#discussion_r1193356688


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java:
##########
@@ -465,6 +465,10 @@ private Path getParentUtil() {
    * @return a new path with the suffix added
    */
   public Path suffix(String suffix) {
+    if (getParent() == null) {
+      return new Path("/", getName()+suffix);

Review Comment:
   nit: space b/w ``getName()`` ``+`` and ``suffix``
   ```
         return new Path("/", getName() + suffix);
   ```



##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java:
##########
@@ -465,6 +465,10 @@ private Path getParentUtil() {
    * @return a new path with the suffix added
    */
   public Path suffix(String suffix) {
+    if (getParent() == null) {
+      return new Path("/", getName()+suffix);
+    }
+
     return new Path(getParent(), getName()+suffix);

Review Comment:
   ``getParent()`` would be computed twice in case the path isn't root, we should extract it into a variable and use it in both places



##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java:
##########
@@ -528,4 +528,11 @@ public void testSerDeser() throws Throwable {
     }
 
   }
+
+  @Test(timeout = 30000)
+  public void testSuffixFromRoot() {
+    Path root = new Path("/");
+    Assert.assertNull(root.getParent());
+    Assert.assertEquals(root.suffix("bar"), new Path("/bar"));

Review Comment:
   Flip the assertions, Expected goes first then the actual. Your expected is ``new Path("/bar")``
   ```
       Assert.assertEquals(new Path("/bar"), root.suffix("bar"));
   ```



-- 
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: common-issues-unsubscribe@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org