You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by in...@apache.org on 2019/08/22 17:22:47 UTC
[hadoop] branch trunk updated: HDFS-14583. FileStatus#toString()
will throw IllegalArgumentException. Contributed by xuzq.
This is an automated email from the ASF dual-hosted git repository.
inigoiri pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new e04dcfd HDFS-14583. FileStatus#toString() will throw IllegalArgumentException. Contributed by xuzq.
e04dcfd is described below
commit e04dcfdc57434858884601ac647522f1160830f7
Author: Inigo Goiri <in...@apache.org>
AuthorDate: Thu Aug 22 10:22:38 2019 -0700
HDFS-14583. FileStatus#toString() will throw IllegalArgumentException. Contributed by xuzq.
---
.../hdfs/protocol/HdfsLocatedFileStatus.java | 2 +-
.../hadoop/hdfs/protocol/HdfsNamedFileStatus.java | 2 +-
.../org/apache/hadoop/hdfs/web/TestJsonUtil.java | 45 ++++++++++++++++++++++
3 files changed, 47 insertions(+), 2 deletions(-)
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 1490e4e..bf4e0d2 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 class HdfsLocatedFileStatus
@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 311f9d0..9434423 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 class HdfsNamedFileStatus extends FileStatus implements HdfsFileStatus {
@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 3ffc35f..2a3680c 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.AclEntryScope.*;
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.HdfsConstants;
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 class TestJsonUtil {
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();
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org