Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8216172

File.renameTo(File dest) should check for NPE at the very beginning

    Details

    • Subcomponent:
    • Resolved In Build:
      b04
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      public boolean renameTo(File dest) {
              SecurityManager security = System.getSecurityManager();
              if (security != null) {
                  security.checkWrite(path);
                  security.checkWrite(dest.path);
              }
              if (dest == null) {
                  throw new NullPointerException();
              }
              if (this.isInvalid() || dest.isInvalid()) {
                  return false;
              }
              return fs.rename(this, dest);
          }

      if a SecurityManager is exists, and dest is null, then execute security.checkWrite(dest.path) will throw nullpoint exception, and if (dest == null) is no meaning.

      the first step should be test if dest is null.

      public boolean renameTo(File dest) {
              if (dest == null) {
                  throw new NullPointerException();
              }
              SecurityManager security = System.getSecurityManager();
              if (security != null) {
                  security.checkWrite(path);
                  security.checkWrite(dest.path);
              }
              if (this.isInvalid() || dest.isInvalid()) {
                  return false;
              }
              return fs.rename(this, dest);
          }


      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bpb Brian Burkhalter
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: