Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6401006

FileOutputStream.open() throws FileNotFoundException for hidden file (win)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.4.2
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Because we had to back out the changes for 6350200, the bug still exists. We need to create a new bug which replicates the appropriate information so that it may be addressed in a later release.

        These are the relevant portions of the description of 6350200.

        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.

        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 );
                }
            }
        }

        Steps to reproduce:
        - Run the provided test. It will create a c:\temp\file1.txt file.
        - Hide the file.
          > attrib +h c:\temp\file1.txt
        - Run the test again.
          > 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)
        - Grant access to the file.
          > attrib -h c:\temp\file1.txt
        - Test will run successfully.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alanb Alan Bateman
                  Reporter:
                  iris Iris Clark
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: