From 49376e445210d5ebe3a99a4e647deecec51f0784 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Fri, 29 Sep 2023 15:03:10 +0000 Subject: [PATCH] 8316000: File.setExecutable silently fails if file does not exist Reviewed-by: alanb --- src/java.base/share/classes/java/io/File.java | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/java.base/share/classes/java/io/File.java b/src/java.base/share/classes/java/io/File.java index 652f28074cc..55c389ddf67 100644 --- 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 class File * file attributes including file permissions. This may be used when finer * manipulation of file permissions is required. * + *

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 class File * 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 class File * file.setReadable(arg, true) * } * + *

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 class File * file attributes including file permissions. This may be used when finer * manipulation of file permissions is required. * + *

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 class File * 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 class File * file.setExecutable(arg, true) * } * + *

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