FULL PRODUCT VERSION :
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
File system on which this occurs is NTFS
A DESCRIPTION OF THE PROBLEM :
When manipulating ACLs of a folder on MS Windows by using AclFileAttributeView (java.nio.file.attribute), it can ends up make any file in it
Setting the ACLs on on folder in MS Windows by using AclFileAttributeView (java.nio.file.attribute), with the same permission it already has (basically, setAcl( getAcl() ) makes the files in that folder unreadable in at least the following case:
- the folder has just been created by the same Java program, and is empty at the time the ACL are touched.
I'm confident this is due to an issue with AclFileAttributeView.setAcl() (or getAcl()) because if don't call it, the files can be read successfully later on.
Put differently, doing :
AclFileAttributeView aclFileAttributes = java.nio.file.Files.getFileAttributeView(<PATH>, AclFileAttributeView.class);
aclFileAttributes.setAcl(aclFileAttributes.getAcl());
should be completly transparent and don't change the outcome of my program, but it does.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
write a small java program which does the following (see my unit test for example), and run it on Windows 7:
1. create a diretory (at this stage, the directory is then empty of any file)
2. "touch" the ACLs of this directory, by just setting it with the same permissions as returned by the getAcl() of the java.nio (in short: call setAcl( getAcl() ) on that folder)
3. create a file inside this directory
4. try reading this file with FileInputStream
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
file should open succesfully, and it does if I don't do step#2 (touch ACL), or if I do between step#3 and #4 (betweem file creation and reading)
ACTUAL -
it throws a java.io.FileNotFoundException with below stack:
java.io.FileNotFoundException: <file path> (Access is denied)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.FileNotFoundException: <file path> (Access is denied)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public void touchAcl(Path path) throws IOException
{
System.out.println("touching Acl at: " + path.toString());
AclFileAttributeView aclFileAttributes = java.nio.file.Files.getFileAttributeView(path, AclFileAttributeView.class);
aclFileAttributes.setAcl(aclFileAttributes.getAcl());
}
@Test
public void testTouchAcl() throws IOException {
String _FOLDER = "D:\\dev\\data\\test";
String _FILE = "D:\\dev\\data\\test\\.md.truc";
// 1. create dir
File folder = new File(_FOLDER);
boolean res = folder.mkdirs();
System.out.println("Directory created? " + res);
// 2. touch acl of the folder
// note: if this is done AFTER the file creation, then no issue...
touchAcl(folder.toPath());
// 3. create file
Path fpath = Paths.get(_FILE);
List<String> lines = Arrays.asList("The first line", "The second line");
Files.write(fpath, lines, Charset.forName("UTF-8"));
System.out.println("File written");
// 4. read
System.out.println("can read folder = " + folder.canRead());
System.out.println("can read file = " + fpath.toFile().canRead());
try (FileInputStream is = new FileInputStream(fpath.toFile())) {
System.out.println("success opening file");
is.close();
} catch (IOException e) {
System.out.println("exception opening file : " + e.getMessage());
throw e;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't touch the ACL, or do it after the file is created
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
File system on which this occurs is NTFS
A DESCRIPTION OF THE PROBLEM :
When manipulating ACLs of a folder on MS Windows by using AclFileAttributeView (java.nio.file.attribute), it can ends up make any file in it
Setting the ACLs on on folder in MS Windows by using AclFileAttributeView (java.nio.file.attribute), with the same permission it already has (basically, setAcl( getAcl() ) makes the files in that folder unreadable in at least the following case:
- the folder has just been created by the same Java program, and is empty at the time the ACL are touched.
I'm confident this is due to an issue with AclFileAttributeView.setAcl() (or getAcl()) because if don't call it, the files can be read successfully later on.
Put differently, doing :
AclFileAttributeView aclFileAttributes = java.nio.file.Files.getFileAttributeView(<PATH>, AclFileAttributeView.class);
aclFileAttributes.setAcl(aclFileAttributes.getAcl());
should be completly transparent and don't change the outcome of my program, but it does.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
write a small java program which does the following (see my unit test for example), and run it on Windows 7:
1. create a diretory (at this stage, the directory is then empty of any file)
2. "touch" the ACLs of this directory, by just setting it with the same permissions as returned by the getAcl() of the java.nio (in short: call setAcl( getAcl() ) on that folder)
3. create a file inside this directory
4. try reading this file with FileInputStream
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
file should open succesfully, and it does if I don't do step#2 (touch ACL), or if I do between step#3 and #4 (betweem file creation and reading)
ACTUAL -
it throws a java.io.FileNotFoundException with below stack:
java.io.FileNotFoundException: <file path> (Access is denied)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.FileNotFoundException: <file path> (Access is denied)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public void touchAcl(Path path) throws IOException
{
System.out.println("touching Acl at: " + path.toString());
AclFileAttributeView aclFileAttributes = java.nio.file.Files.getFileAttributeView(path, AclFileAttributeView.class);
aclFileAttributes.setAcl(aclFileAttributes.getAcl());
}
@Test
public void testTouchAcl() throws IOException {
String _FOLDER = "D:\\dev\\data\\test";
String _FILE = "D:\\dev\\data\\test\\.md.truc";
// 1. create dir
File folder = new File(_FOLDER);
boolean res = folder.mkdirs();
System.out.println("Directory created? " + res);
// 2. touch acl of the folder
// note: if this is done AFTER the file creation, then no issue...
touchAcl(folder.toPath());
// 3. create file
Path fpath = Paths.get(_FILE);
List<String> lines = Arrays.asList("The first line", "The second line");
Files.write(fpath, lines, Charset.forName("UTF-8"));
System.out.println("File written");
// 4. read
System.out.println("can read folder = " + folder.canRead());
System.out.println("can read file = " + fpath.toFile().canRead());
try (FileInputStream is = new FileInputStream(fpath.toFile())) {
System.out.println("success opening file");
is.close();
} catch (IOException e) {
System.out.println("exception opening file : " + e.getMessage());
throw e;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't touch the ACL, or do it after the file is created