diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsLocatedFileStatus.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsLocatedFileStatus.java index 1490e4e4ef..bf4e0d2f9f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsLocatedFileStatus.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsLocatedFileStatus.java @@ -108,7 +108,7 @@ public void setGroup(String group) { @Override public boolean isSymlink() { - return uSymlink != null; + return uSymlink != null && uSymlink.length > 0; } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsNamedFileStatus.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsNamedFileStatus.java index 311f9d0e51..9434423d72 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsNamedFileStatus.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsNamedFileStatus.java @@ -95,7 +95,7 @@ public void setGroup(String group) { @Override public boolean isSymlink() { - return uSymlink != null; + return uSymlink != null && uSymlink.length > 0; } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestJsonUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestJsonUtil.java index 3ffc35fe6e..2a3680cdb1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestJsonUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestJsonUtil.java @@ -21,6 +21,8 @@ import static org.apache.hadoop.fs.permission.AclEntryType.*; import static org.apache.hadoop.fs.permission.FsAction.*; import static org.apache.hadoop.hdfs.server.namenode.AclTestHelpers.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.io.IOException; import java.util.EnumSet; @@ -47,6 +49,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus.Flags; import org.apache.hadoop.io.erasurecode.ECSchema; +import org.apache.hadoop.test.LambdaTestUtils; import org.apache.hadoop.util.Time; import org.junit.Assert; import org.junit.Test; @@ -107,6 +110,48 @@ public void testHdfsFileStatusWithEcPolicy() throws IOException { Assert.assertEquals(fstatus, fs2); } + /** + * Verify isSymlink when symlink ie empty. + */ + @Test + public void testHdfsFileStatus() throws Exception { + HdfsFileStatus hdfsFileStatus = new HdfsFileStatus.Builder() + .replication(1) + .blocksize(1024) + .perm(new FsPermission((short) 777)) + .owner("owner") + .group("group") + .symlink(new byte[0]) + .path(new byte[0]) + .fileId(1010) + .isdir(true) + .build(); + + assertFalse(hdfsFileStatus.isSymlink()); + LambdaTestUtils.intercept(IOException.class, + "Path " + hdfsFileStatus.getPath() + " is not a symbolic link", + () -> hdfsFileStatus.getSymlink()); + + String expectString = new StringBuilder() + .append("HdfsLocatedFileStatus") + .append("{") + .append("path=" + null) + .append("; isDirectory=" + true) + .append("; modification_time=" + 0) + .append("; access_time=" + 0) + .append("; owner=" + "owner") + .append("; group=" + "group") + .append("; permission=" + "r----x--t") + .append("; isSymlink=" + false) + .append("; hasAcl=" + false) + .append("; isEncrypted=" + false) + .append("; isErasureCoded=" + false) + .append("}") + .toString(); + + assertEquals(expectString, hdfsFileStatus.toString()); + } + @Test public void testHdfsFileStatusWithoutEcPolicy() throws IOException { final long now = Time.now();