Skip to content
Permalink
Browse files
8241619: (fs) Files.newByteChannel(path, Set.of(CREATE_NEW, READ)) do…
…es not throw a FileAlreadyExistsException when the file exists

Reviewed-by: alanb
  • Loading branch information
Brian Burkhalter committed Mar 23, 2021
1 parent e9321cd commit 8fa34e40437ef0452287a51ef3faac4f033aa7c2
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 14 deletions.
@@ -209,8 +209,8 @@ protected AsynchronousFileChannel() {
* FileAttribute file-attributes} to set atomically when creating the file.
*
* <p> The new channel is created by invoking the {@link
* FileSystemProvider#newFileChannel newFileChannel} method on the
* provider that created the {@code Path}.
* FileSystemProvider#newAsynchronousFileChannel newAsynchronousFileChannel}
* method on the provider that created the {@code Path}.
*
* @param file
* The path of the file to open or create
@@ -232,6 +232,12 @@ protected AsynchronousFileChannel() {
* support creating asynchronous file channels, or an unsupported
* open option is specified, or the array contains an attribute that
* cannot be set atomically when creating the file
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* and the file is being opened for writing
* <i>(<a href="../file/package-summary.html#optspecex">optional
* specific exception</a>)</i>
* @throws IOException
* If an I/O error occurs
* @throws SecurityException
@@ -287,6 +293,12 @@ public static AsynchronousFileChannel open(Path file,
* If the {@code file} is associated with a provider that does not
* support creating file channels, or an unsupported open option is
* specified
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* and the file is being opened for writing
* <i>(<a href="../file/package-summary.html#optspecex">optional
* specific exception</a>)</i>
* @throws IOException
* If an I/O error occurs
* @throws SecurityException
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -270,6 +270,12 @@ protected FileChannel() { }
* support creating file channels, or an unsupported open option is
* specified, or the array contains an attribute that cannot be set
* atomically when creating the file
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* and the file is being opened for writing
* <i>(<a href="../file/package-summary.html#optspecex">optional
* specific exception</a>)</i>
* @throws IOException
* If an I/O error occurs
* @throws SecurityException
@@ -319,6 +325,12 @@ public static FileChannel open(Path path,
* If the {@code path} is associated with a provider that does not
* support creating file channels, or an unsupported open option is
* specified
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* and the file is being opened for writing
* <i>(<a href="../file/package-summary.html#optspecex">optional
* specific exception</a>)</i>
* @throws IOException
* If an I/O error occurs
* @throws SecurityException
@@ -208,6 +208,10 @@ public static InputStream newInputStream(Path path, OpenOption... options)
* if {@code options} contains an invalid combination of options
* @throws UnsupportedOperationException
* if an unsupported option is specified
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* <i>(optional specific exception)</i>
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
@@ -349,9 +353,10 @@ public static OutputStream newOutputStream(Path path, OpenOption... options)
* if an unsupported open option is specified or the array contains
* attributes that cannot be set atomically when creating the file
* @throws FileAlreadyExistsException
* if a file of that name already exists and the {@link
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* <i>(optional specific exception)</i>
* and the file is being opened for writing <i>(optional specific
* exception)</i>
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
@@ -395,9 +400,10 @@ public static SeekableByteChannel newByteChannel(Path path,
* @throws UnsupportedOperationException
* if an unsupported open option is specified
* @throws FileAlreadyExistsException
* if a file of that name already exists and the {@link
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* <i>(optional specific exception)</i>
* and the file is being opened for writing <i>(optional specific
* exception)</i>
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
@@ -637,7 +643,7 @@ public static DirectoryStream<Path> newDirectoryStream(Path dir,
* if the array contains an attribute that cannot be set atomically
* when creating the file
* @throws FileAlreadyExistsException
* if a file of that name already exists
* If a file of that name already exists
* <i>(optional specific exception)</i>
* @throws IOException
* if an I/O error occurs or the parent directory does not exist
@@ -2981,6 +2987,10 @@ public static BufferedReader newBufferedReader(Path path) throws IOException {
* if an I/O error occurs opening or creating the file
* @throws UnsupportedOperationException
* if an unsupported option is specified
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* <i>(optional specific exception)</i>
* @throws SecurityException
* In the case of the default provider, and a security manager is
* installed, the {@link SecurityManager#checkWrite(String) checkWrite}
@@ -3027,6 +3037,10 @@ public static BufferedWriter newBufferedWriter(Path path, Charset cs,
* if an I/O error occurs opening or creating the file
* @throws UnsupportedOperationException
* if an unsupported option is specified
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* <i>(optional specific exception)</i>
* @throws SecurityException
* In the case of the default provider, and a security manager is
* installed, the {@link SecurityManager#checkWrite(String) checkWrite}
@@ -3478,6 +3492,10 @@ public static List<String> readAllLines(Path path) throws IOException {
* if an I/O error occurs writing to or creating the file
* @throws UnsupportedOperationException
* if an unsupported option is specified
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* <i>(optional specific exception)</i>
* @throws SecurityException
* In the case of the default provider, and a security manager is
* installed, the {@link SecurityManager#checkWrite(String) checkWrite}
@@ -3542,6 +3560,10 @@ public static Path write(Path path, byte[] bytes, OpenOption... options)
* text cannot be encoded using the specified charset
* @throws UnsupportedOperationException
* if an unsupported option is specified
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* <i>(optional specific exception)</i>
* @throws SecurityException
* In the case of the default provider, and a security manager is
* installed, the {@link SecurityManager#checkWrite(String) checkWrite}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -103,7 +103,7 @@
* provider} with a parameter that is an object created by another provider,
* will throw {@link java.nio.file.ProviderMismatchException}. </p>
*
* <h2>Optional Specific Exceptions</h2>
* <h2><a id="optspecex">Optional Specific Exceptions</a></h2>
* Most of the methods defined by classes in this package that access the
* file system specify that {@link java.io.IOException} be thrown when an I/O
* error occurs. In some cases, these methods define specific I/O exceptions
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -451,6 +451,10 @@ public InputStream newInputStream(Path path, OpenOption... options)
* if an unsupported option is specified
* @throws IOException
* if an I/O error occurs
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* <i>(optional specific exception)</i>
* @throws SecurityException
* In the case of the default provider, and a security manager is
* installed, the {@link SecurityManager#checkWrite(String) checkWrite}
@@ -507,6 +511,11 @@ public OutputStream newOutputStream(Path path, OpenOption... options)
* @throws UnsupportedOperationException
* If this provider that does not support creating file channels,
* or an unsupported open option or file attribute is specified
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* and the file is being opened for writing
* <i>(optional specific exception)</i>
* @throws IOException
* If an I/O error occurs
* @throws SecurityException
@@ -555,6 +564,11 @@ public FileChannel newFileChannel(Path path,
* If this provider that does not support creating asynchronous file
* channels, or an unsupported open option or file attribute is
* specified
* @throws FileAlreadyExistsException
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* and the file is being opened for writing
* <i>(optional specific exception)</i>
* @throws IOException
* If an I/O error occurs
* @throws SecurityException
@@ -594,8 +608,9 @@ public AsynchronousFileChannel newAsynchronousFileChannel(Path path,
* if an unsupported open option is specified or the array contains
* attributes that cannot be set atomically when creating the file
* @throws FileAlreadyExistsException
* if a file of that name already exists and the {@link
* If a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* and the file is being opened for writing
* <i>(optional specific exception)</i>
* @throws IOException
* if an I/O error occurs
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,10 @@
*
* <p> Unless otherwise noted, passing a {@code null} argument to a constructor
* or method in any class or interface in this package will cause a {@link
* java.lang.NullPointerException NullPointerException} to be thrown.
* java.lang.NullPointerException NullPointerException} to be thrown. In some
* cases methods which are specified to throw an {@code IOException} may throw
* a more specific <i><a href="../package-summary.html#optspecex">optional
* specific exception</a></i>.
*
* @since 1.7
*/

0 comments on commit 8fa34e4

Please sign in to comment.