-
Bug
-
Resolution: Fixed
-
P3
-
5.0
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2160320 | 5.0-pool | Robert Mckenna | P3 | Closed | Won't Fix |
FULL PRODUCT VERSION :
G:\projects>java -version
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When opening a hidden file for write access the FileNotFoundException exception is thrown. If you remove the hidden attribute (via attrib) the exception is not thrown and application works correctly.
I did find bug ID 4624413. But problem still seem to exists.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run attached java code. It will create a c:\temp\file1.txt file.
Hide the file: on command prompt type: "attrib +h c:\temp\file1.txt"
Run attached code again, error will occur.
To revert: On command prompt type: "attrib -h c:\temp\file1.txt"
Running code again will write the same content with no error message
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Hidden file to be updated with new content.
ACTUAL -
G:\projects>java -cp . HiddenFileTest
java.io.FileNotFoundException: C:\temp\file1.txt (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at HiddenFileTest.main(HiddenFileTest.java:7)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
G:\projects>java -cp . HiddenFileTest
java.io.FileNotFoundException: C:\temp\file1.txt (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at HiddenFileTest.main(HiddenFileTest.java:7)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
public class HiddenFileTest {
// Main function, launches JFileChooser to select a directory
public static void main( String[] args ) {
try {
FileWriter fw = new FileWriter( "C:\\temp\\file1.txt" );
PrintWriter out = new PrintWriter( fw );
out.println( "This is a test 2" );
out.close();
} catch( IOException e ) {
e.printStackTrace( System.out );
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Did not find one. Something along the lines of
File f = new File( ... )
f.setHidden( false )
... update content of file via FileOutputStream ...
f.setHidden( true )
would be a workaround
Release Regression From : 1.4.1
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
G:\projects>java -version
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When opening a hidden file for write access the FileNotFoundException exception is thrown. If you remove the hidden attribute (via attrib) the exception is not thrown and application works correctly.
I did find bug ID 4624413. But problem still seem to exists.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run attached java code. It will create a c:\temp\file1.txt file.
Hide the file: on command prompt type: "attrib +h c:\temp\file1.txt"
Run attached code again, error will occur.
To revert: On command prompt type: "attrib -h c:\temp\file1.txt"
Running code again will write the same content with no error message
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Hidden file to be updated with new content.
ACTUAL -
G:\projects>java -cp . HiddenFileTest
java.io.FileNotFoundException: C:\temp\file1.txt (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at HiddenFileTest.main(HiddenFileTest.java:7)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
G:\projects>java -cp . HiddenFileTest
java.io.FileNotFoundException: C:\temp\file1.txt (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at HiddenFileTest.main(HiddenFileTest.java:7)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
public class HiddenFileTest {
// Main function, launches JFileChooser to select a directory
public static void main( String[] args ) {
try {
FileWriter fw = new FileWriter( "C:\\temp\\file1.txt" );
PrintWriter out = new PrintWriter( fw );
out.println( "This is a test 2" );
out.close();
} catch( IOException e ) {
e.printStackTrace( System.out );
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Did not find one. Something along the lines of
File f = new File( ... )
f.setHidden( false )
... update content of file via FileOutputStream ...
f.setHidden( true )
would be a workaround
Release Regression From : 1.4.1
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
- backported by
-
JDK-2160320 FileOutputStream.open() throws FileNotFoundException for hidden file (win)
-
- Closed
-
- relates to
-
JDK-8047342 FileOutputStream fails with Access denied when file has "hidden" or "system" attributes set
-
- Open
-
-
JDK-6364894 FileOutputStream is able to modify/write to read-only filessince Mustang-b63 (win)
-
- Closed
-
-
JDK-6401006 FileOutputStream.open() throws FileNotFoundException for hidden file (win)
-
- Closed
-