Skip to content

Commit

Permalink
HDFS-14583. FileStatus#toString() will throw IllegalArgumentException…
Browse files Browse the repository at this point in the history
…. Contributed by xuzq.
  • Loading branch information
Inigo Goiri authored and ahussein committed Oct 29, 2019
1 parent 1dc3d89 commit d2e8097
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void setGroup(String group) {

@Override
public boolean isSymlink() {
return uSymlink != null;
return uSymlink != null && uSymlink.length > 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setGroup(String group) {

@Override
public boolean isSymlink() {
return uSymlink != null;
return uSymlink != null && uSymlink.length > 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d2e8097

Please sign in to comment.