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

(fs) Files.newByteChannel(path, Set.of(CREATE_NEW, READ)) does not throw a FileAlreadyExistsException when the file exists

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P5
    • 17
    • core-libs
    • None
    • behavioral
    • minimal
    • The change would document existing behavior.
    • Java API
    • SE

    Description

      Summary

      Add @throws FileAlreadyExistsException to the specifications of some methods in some classes in java.nio.channels.AsynchronousFileChannel, java.nio.channels.FileChannel, java.nio.file.Files, and java.nio.file.spi.FileSystemProvider which are susceptible to throwing this exception.

      Problem

      A number of methods in java.nio.channels.AsynchronousFileChannel, java.nio.channels.FileChannel, java.nio.file.Files, and java.nio.file.spi.FileSystemProvider will throw a FileAlreadyExistsException if the file is being opened for appending or writing and the option java.nio.file.StandardOpenOption.CREATE_NEW is specified.

      Solution

      While FileAlreadyExistsException is an "optional specific exception," a specialized subclass of IOException intended to convey a more precise reason for a failure than would a plain IOException, hence not strictly required to be documented explicitly, it is in fact declared in some places but not in others. This change would add it to the specifications of those methods wherein it may occur thereby making the overall API specification more consistent.

      Specification

      Please refer to the attached archive specdiff-8241619.01.zip.

      Attachments

        Issue Links

          Activity

            People

              bpb Brian Burkhalter
              lancea Lance Andersen
              Alan Bateman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: