(fs) Support current working directory target in SecureDirectoryStream.move

XMLWordPrintable

    • Type: CSR
    • Resolution: Unresolved
    • Priority: P4
    • 27
    • Component/s: core-libs
    • None
    • behavioral
    • minimal
    • The compatibility risk should be low as, instead of `NullPointerException` being thrown, a relative target path will be created with respect to the current working directory.
    • Java API
    • SE

      Summary

      Change SecureDirectoryStream.move(Path,SecureDirectoryStream<Path>,Path) so that a targetdir parameter value of null indicates the current working directory when targetpath is relative.

      Problem

      Currently a targetdir value of null will result in a NullPointerException when targetpath is relative. It would be more useful if a null value of targetdir were to designate the current working directory as the starting point for a relative path supplied in targetpath.

      Solution

      Modify SecureDirectoryStream.move such that a null-valued targetdir parameter indicates that a relative path supplied via the targetpath parameter is with respect to the current working directory.

      Specification

      --- a/src/java.base/share/classes/java/nio/file/SecureDirectoryStream.java
      +++ b/src/java.base/share/classes/java/nio/file/SecureDirectoryStream.java
      @@ -185,8 +185,8 @@ SeekableByteChannel newByteChannel(T path,
           /**
            * Move a file from this directory to another directory.
            *
      -     * <p> This method works in a similar manner to {@link Files#move move}
      -     * method when the {@link StandardCopyOption#ATOMIC_MOVE ATOMIC_MOVE} option
      +     * <p> This method works in a similar manner to {@link Files#move Files.move}
      +     * when the {@link StandardCopyOption#ATOMIC_MOVE ATOMIC_MOVE} option
            * is specified. That is, this method moves a file as an atomic file system
            * operation. If the {@code srcpath} parameter is an {@link Path#isAbsolute
            * absolute} path then it locates the source file. If the parameter is a
      @@ -194,14 +194,15 @@ SeekableByteChannel newByteChannel(T path,
            * the {@code targetpath} parameter is absolute then it locates the target
            * file (the {@code targetdir} parameter is ignored). If the parameter is
            * a relative path it is located relative to the open directory identified
      -     * by the {@code targetdir} parameter. In all cases, if the target file
      -     * exists then it is implementation specific if it is replaced or this
      -     * method fails.
      +     * by the {@code targetdir} parameter, unless {@code targetdir} is
      +     * {@code null}, in which case it is located relative to the current
      +     * working directory. In all cases, if the target file exists then it is
      +     * implementation specific if it is replaced or this method fails.
            *
            * @param   srcpath
            *          the name of the file to move
            * @param   targetdir
      -     *          the destination directory
      +     *          the destination directory; can be {@code null}
            * @param   targetpath
            *          the name to give the file in the destination directory
            *
      

            Assignee:
            Brian Burkhalter
            Reporter:
            Brian Burkhalter
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: