Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-17689

Avoid Potential NPE in org.apache.hadoop.fs

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.4.0
    • Component/s: fs
    • Target Version/s:

      Description

      https://github.com/apache/hadoop/blob/f40e3eb0590f85bb42d2471992bf5d524628fdd6/
      Hello,
      Our code analyses found the following potential NPE:

       

        public Path getParent() {
          String path = uri.getPath();
          int lastSlash = path.lastIndexOf('/');
          int start = startPositionWithoutWindowsDrive(path);
          if ((path.length() == start) ||               // empty path
              (lastSlash == start && path.length() == start+1)) { // at root
            return null;
          }
      

       

        public FSDataOutputStream createInternal (Path f,
            EnumSet<CreateFlag> flag, FsPermission absolutePermission, int bufferSize,
            short replication, long blockSize, Progressable progress,
            ChecksumOpt checksumOpt, boolean createParent) throws IOException {
          checkPath(f);
          
          // Default impl assumes that permissions do not matter
          // calling the regular create is good enough.
          // FSs that implement permissions should override this.    if (!createParent) { // parent must exist.
            // since this.create makes parent dirs automatically
            // we must throw exception if parent does not exist.
            final FileStatus stat = getFileStatus(f.getParent()); // NPE!
            if (stat == null) {
              throw new FileNotFoundException("Missing parent:" + f);
            }
      

      Full Trace:

      1. Return null to caller
      https://github.com/apache/hadoop/blob/f40e3eb0590f85bb42d2471992bf5d524628fdd6/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java#L432

      2. The return value of function getParent is used as the 1st parameter in function getFileStatus (the return value of function getParent can be null)
      https://github.com/apache/hadoop/blob/f40e3eb0590f85bb42d2471992bf5d524628fdd6/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java#L93

      3. f is used as the 1st parameter in function checkPath (f can be null)
      https://github.com/apache/hadoop/blob/f40e3eb0590f85bb42d2471992bf5d524628fdd6/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java#L127

      4. path is passed as the this pointer to function toUri (path can be null)
      https://github.com/apache/hadoop/blob/f40e3eb0590f85bb42d2471992bf5d524628fdd6/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L369

      Commit: f40e3eb0590f85bb42d2471992bf5d524628fdd6

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vjasani Viraj Jasani
                Reporter:
                ErrReporter Error Reporter
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m