Skip to content

Commit e04dcfd

Browse files
author
Inigo Goiri
committed
HDFS-14583. FileStatus#toString() will throw IllegalArgumentException. Contributed by xuzq.
1 parent 63c295e commit e04dcfd

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsLocatedFileStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void setGroup(String group) {
108108

109109
@Override
110110
public boolean isSymlink() {
111-
return uSymlink != null;
111+
return uSymlink != null && uSymlink.length > 0;
112112
}
113113

114114
@Override

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsNamedFileStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void setGroup(String group) {
9595

9696
@Override
9797
public boolean isSymlink() {
98-
return uSymlink != null;
98+
return uSymlink != null && uSymlink.length > 0;
9999
}
100100

101101
@Override

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestJsonUtil.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import static org.apache.hadoop.fs.permission.AclEntryType.*;
2222
import static org.apache.hadoop.fs.permission.FsAction.*;
2323
import static org.apache.hadoop.hdfs.server.namenode.AclTestHelpers.*;
24+
import static org.junit.Assert.assertEquals;
25+
import static org.junit.Assert.assertFalse;
2426

2527
import java.io.IOException;
2628
import java.util.EnumSet;
@@ -47,6 +49,7 @@
4749
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
4850
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus.Flags;
4951
import org.apache.hadoop.io.erasurecode.ECSchema;
52+
import org.apache.hadoop.test.LambdaTestUtils;
5053
import org.apache.hadoop.util.Time;
5154
import org.junit.Assert;
5255
import org.junit.Test;
@@ -107,6 +110,48 @@ public void testHdfsFileStatusWithEcPolicy() throws IOException {
107110
Assert.assertEquals(fstatus, fs2);
108111
}
109112

113+
/**
114+
* Verify isSymlink when symlink ie empty.
115+
*/
116+
@Test
117+
public void testHdfsFileStatus() throws Exception {
118+
HdfsFileStatus hdfsFileStatus = new HdfsFileStatus.Builder()
119+
.replication(1)
120+
.blocksize(1024)
121+
.perm(new FsPermission((short) 777))
122+
.owner("owner")
123+
.group("group")
124+
.symlink(new byte[0])
125+
.path(new byte[0])
126+
.fileId(1010)
127+
.isdir(true)
128+
.build();
129+
130+
assertFalse(hdfsFileStatus.isSymlink());
131+
LambdaTestUtils.intercept(IOException.class,
132+
"Path " + hdfsFileStatus.getPath() + " is not a symbolic link",
133+
() -> hdfsFileStatus.getSymlink());
134+
135+
String expectString = new StringBuilder()
136+
.append("HdfsLocatedFileStatus")
137+
.append("{")
138+
.append("path=" + null)
139+
.append("; isDirectory=" + true)
140+
.append("; modification_time=" + 0)
141+
.append("; access_time=" + 0)
142+
.append("; owner=" + "owner")
143+
.append("; group=" + "group")
144+
.append("; permission=" + "r----x--t")
145+
.append("; isSymlink=" + false)
146+
.append("; hasAcl=" + false)
147+
.append("; isEncrypted=" + false)
148+
.append("; isErasureCoded=" + false)
149+
.append("}")
150+
.toString();
151+
152+
assertEquals(expectString, hdfsFileStatus.toString());
153+
}
154+
110155
@Test
111156
public void testHdfsFileStatusWithoutEcPolicy() throws IOException {
112157
final long now = Time.now();

0 commit comments

Comments
 (0)