Summary
Change specifications of the java.io.File
methods setExecutable
and setReadable
to match longstanding behavior.
Problem
File.setExecutable
and File.setReadable
are no-ops on Windows and simply return the value of the executable
or readable
parameter, respectively. This does not match the specification which expects that true
will be returned on success, and false
on failure. Changing the implementation to something more in line with the current specification would be risky and likely to break existing code as these methods are quite old.
Solution
Modify the specification to match longstanding behavior.
Specification
-
-- a/src/java.base/share/classes/java/io/File.java
+++ b/src/java.base/share/classes/java/io/File.java
@@ -1621,6 +1621,12 @@ public boolean setWritable(boolean writable) {
* file attributes including file permissions. This may be used when finer
* manipulation of file permissions is required.
*
+ * <p> If the platform supports setting a file's read permission, but
+ * the user does not have permission to change the access permissions of
+ * this abstract pathname, then the operation will fail. If the platform
+ * does not support setting a file's read permission, this method does
+ * nothing and returns the value of the {@code readable} parameter.
+ *
* @param readable
* If {@code true}, sets the access permission to allow read
* operations; if {@code false} to disallow read operations
@@ -1632,12 +1638,9 @@ public boolean setWritable(boolean writable) {
* permission from that of others, then the permission will apply to
* everybody, regardless of this value.
*
- * @return {@code true} if and only if the operation succeeded. The
- * operation will fail if the user does not have permission to
- * change the access permissions of this abstract pathname. If
- * {@code readable} is {@code false} and the underlying
- * file system does not implement a read permission, then the
- * operation will fail.
+ * @return {@code true} if the operation succeeds, {@code false} if it
+ * fails, or the value of the {@code readable} parameter if
+ * setting the read permission is not supported.
*
* @throws SecurityException
* If a security manager exists and its {@link
@@ -1671,16 +1674,19 @@ public boolean setReadable(boolean readable, boolean ownerOnly) {
* file.setReadable(arg, true)
* }
*
+ * <p> If the platform supports setting a file's read permission, but
+ * the user does not have permission to change the access permissions of
+ * this abstract pathname, then the operation will fail. If the platform
+ * does not support setting a file's read permission, this method does
+ * nothing and returns the value of the {@code readable} parameter.
+ *
* @param readable
* If {@code true}, sets the access permission to allow read
* operations; if {@code false} to disallow read operations
*
- * @return {@code true} if and only if the operation succeeded. The
- * operation will fail if the user does not have permission to
- * change the access permissions of this abstract pathname. If
- * {@code readable} is {@code false} and the underlying
- * file system does not implement a read permission, then the
- * operation will fail.
+ * @return {@code true} if the operation succeeds, {@code false} if it
+ * fails, or the value of the {@code readable} parameter if
+ * setting the read permission is not supported.
*
* @throws SecurityException
* If a security manager exists and its {@link
@@ -1703,6 +1709,12 @@ public boolean setReadable(boolean readable) {
* file attributes including file permissions. This may be used when finer
* manipulation of file permissions is required.
*
+ * <p> If the platform supports setting a file's execute permission, but
+ * the user does not have permission to change the access permissions of
+ * this abstract pathname, then the operation will fail. If the platform
+ * does not support setting a file's execute permission, this method does
+ * nothing and returns the value of the {@code executable} parameter.
+ *
* @param executable
* If {@code true}, sets the access permission to allow execute
* operations; if {@code false} to disallow execute operations
@@ -1714,12 +1726,9 @@ public boolean setReadable(boolean readable) {
* execute permission from that of others, then the permission will
* apply to everybody, regardless of this value.
*
- * @return {@code true} if and only if the operation succeeded. The
- * operation will fail if the user does not have permission to
- * change the access permissions of this abstract pathname. If
- * {@code executable} is {@code false} and the underlying
- * file system does not implement an execute permission, then the
- * operation will fail.
+ * @return {@code true} if the operation succeeds, {@code false} if it
+ * fails, or the value of the {@code executable} parameter if
+ * setting the execute permission is not supported.
*
* @throws SecurityException
* If a security manager exists and its {@link
@@ -1753,16 +1762,19 @@ public boolean setExecutable(boolean executable, boolean ownerOnly) {
* file.setExecutable(arg, true)
* }
*
+ * <p> If the platform supports setting a file's execute permission, but
+ * the user does not have permission to change the access permissions of
+ * this abstract pathname, then the operation will fail. If the platform
+ * does not support setting a file's execute permission, this method does
+ * nothing and returns the value of the {@code executable} parameter.
+ *
* @param executable
* If {@code true}, sets the access permission to allow execute
* operations; if {@code false} to disallow execute operations
*
- * @return {@code true} if and only if the operation succeeded. The
- * operation will fail if the user does not have permission to
- * change the access permissions of this abstract pathname. If
- * {@code executable} is {@code false} and the underlying
- * file system does not implement an execute permission, then the
- * operation will fail.
+ * @return {@code true} if the operation succeeds, {@code false} if it
+ * fails, or the value of the {@code executable} parameter if
+ * setting the execute permission is not supported.
*
* @throws SecurityException
* If a security manager exists and its {@link
- csr of
-
JDK-8316000 File.setExecutable silently fails if file does not exist
-
- Resolved
-