New bug in HDFS "listFiles" method

to create new topics or reply. | New User Registration

This topic contains 3 replies, has 2 voices, and was last updated by  Nicholas Sze 1 year, 10 months ago.

  • Creator
  • #36781

    Arnaud LINZ


    We migrated from HDP2.0 alpha to beta and we found a regression :

    // FileSystem filesys is the HDFS File System
    // Path path is a relative path such as new Path("test")
    final RemoteIterator iter = filesys.listFiles(path, true);
                while (iter.hasNext()) {

    fails in NullPointerException when path is relative and contains a subdirectory.
    The stack trace shows that when trying to make an absolute path of the subdirectory,it calls

    final public LocatedFileStatus makeQualifiedLocated(URI defaultUri,
          Path path) {
        return new LocatedFileStatus(getLen(), isDir(), getReplication(),
            getBlockSize(), getModificationTime(),
            getPermission(), getOwner(), getGroup(),
            isSymlink() ? new Path(getSymlink()) : null,
                defaultUri, null), // fully-qualify path

    but getFullPath code :

       * Get the full path
       * @param parent the parent path
       * @return the full path
      final public Path getFullPath(final Path parent) {
        if (isEmptyLocalName()) {
          return parent;
        return new Path(parent, getLocalName());

    when called with a relative path as a parent still returns a relative path, and that makes
    getFullPath(path)).makeQualified(defaultUri, null)
    fail because of the null argument that is passed.

    A workaround is to call a method like

    public static Path fixRelativePart(Path path) throws IOException {
            final Path retVal;
            if (path.isUriPathAbsolute()) {
                retVal = path;
            else {
                retVal = new Path(getFileSystem().getWorkingDirectory(), path);
            return retVal;

    on path before trying to call listFiles.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘New bug in HDFS "listFiles" method’ is closed to new replies.

  • Author
  • #36927

    Nicholas Sze

    Hi Arnaud, thanks for posting your discovery. I just have verified that the bug does exist. It is also in current Apache trunk. I will file a JIRA for fixing it. Thank again!


    Arnaud LINZ

    I forgot the stack trace :

    at org.apache.hadoop.fs.Path.(
    at org.apache.hadoop.fs.Path.makeQualified(
    at org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus.makeQualifiedLocated(
    at org.apache.hadoop.hdfs.DistributedFileSystem$15.hasNext(
    at org.apache.hadoop.fs.FileSystem$5.hasNext(
    at com.bouygtel.ganesh.hdfs.HdfsTools.listDirectory(

Viewing 3 replies - 1 through 3 (of 3 total)
Hortonworks Data Platform
The Hortonworks Data Platform is a 100% open source distribution of Apache Hadoop that is truly enterprise grade having been built, tested and hardened with enterprise rigor.
Get started with Sandbox
Hortonworks Sandbox is a self-contained virtual machine with Apache Hadoop pre-configured alongside a set of hands-on, step-by-step Hadoop tutorials.
Modern Data Architecture
Tackle the challenges of big data. Hadoop integrates with existing EDW, RDBMS and MPP systems to deliver lower cost, higher capacity infrastructure.