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

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

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b63
    • CPU:
      x86
    • OS:
      windows_xp

      Backports

        Description

        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.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jhangalsunw Jayalaxmi Hangal (Inactive)
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: