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

File.canWrite() returns false for the "My Documents" directory (win)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.4.2, 6u10, 6u16
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b30
    • CPU:
      x86
    • OS:
      windows_xp, windows_2008, windows_vista
    • Verification:
      Not verified

      Backports

        Description

        Name: rmT116609 Date: 10/17/2003


        FULL PRODUCT VERSION :
        java version "1.4.2_01"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
        Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

        FULL OS VERSION :
        Microsoft Windows XP [Version 5.1.2600]

        A DESCRIPTION OF THE PROBLEM :
        File.canWrite() returns false for the user's "My Documents" directory, when specified as the path "c:\documents and settings\<username>\my documents".

        This is incorrect as the "My Documents" directory is writable.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile and run the test program below. When the Swing file chooser appears, navigate to your "My Documents" directory via
        c:\documents and settings\<your username>\my documents
        Click OK. The debug output will indicate that this directory is not writable.
        Some subdirectories under "My Documents" are writable - here's some sample output:
        $ javac Foo.java && java Foo
        ** Not writable **: C:\Documents and Settings\johnc\My Documents
        Writable: C:\Documents and Settings\johnc\My Documents\Visual Studio Projects
        Writable: H:
        Note, this is not a Swing problem, as the same happens when creating a File object for "c:\documents and settings\johnc\my documents" and calling canWrite() on that.



        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        canWrite() should return true for the "My Documents" directory.
        ACTUAL -
        canWrite() returns false for the "My Documents" directory.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.swing.*;
        import javax.swing.filechooser.*;
        import java.awt.*;
        import java.io.File;

        public class Foo extends JFrame {
            public static void main(String[] args) {
                JFrame frame = new JFrame();
                JFileChooser chooser = new JFileChooser();
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.setFileHidingEnabled(false);

                while (true) {
                    int option = chooser.showDialog(frame, "OK");
                    if (option != JFileChooser.APPROVE_OPTION)
                        continue;

                    File file = chooser.getSelectedFile();

        // try {
        // file = file.getAbsoluteFile();
        // file = file.getCanonicalFile();
        // } catch (Exception e) { System.out.println("e"); }

                    if (file.canWrite()) {
                        System.out.println("Writable: "+file);
                    } else {
                        System.out.println("** Not writable **: "+file);
                    }
                    chooser.setCurrentDirectory(file);
                }
            }
        }

        ---------- END SOURCE ----------
        (Incident Review ID: 216229)
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                alanb Alan Bateman
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: