Home Forums HDFS New bug in HDFS "listFiles" method

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

  • Creator
    Topic
  • #36781

    Arnaud LINZ
    Member

    Hello,

    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()) {
                    retVal.add(iter.next());
              }
     }
    

    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(),
            getAccessTime(),
            getPermission(), getOwner(), getGroup(),
            isSymlink() ? new Path(getSymlink()) : null,
            (getFullPath(path)).makeQualified(
                defaultUri, null), // fully-qualify path
            DFSUtil.locatedBlocks2Locations(getBlockLocations()));
      }
    

    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
    Replies
  • #36927
    Collapse
    #36926

    Nicholas Sze
    Participant

    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!

    Collapse
    #36783

    Arnaud LINZ
    Member

    I forgot the stack trace :

    java.lang.NullPointerException
    at org.apache.hadoop.fs.Path.(Path.java:105)
    at org.apache.hadoop.fs.Path.makeQualified(Path.java:421)
    at org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus.makeQualifiedLocated(HdfsLocatedFileStatus.java:72)
    at org.apache.hadoop.hdfs.DistributedFileSystem$15.hasNext(DistributedFileSystem.java:749)
    at org.apache.hadoop.fs.FileSystem$5.hasNext(FileSystem.java:1845)
    at com.bouygtel.ganesh.hdfs.HdfsTools.listDirectory(HdfsTools.java:152)
    (…)

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