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

In Win95 JDK 1.1.1, File.delete() fails to delete the file from disk

    XMLWordPrintable

Details

    • x86
    • windows_95

    Description

      In Win95 JDK 1.1.1, File.delete() fails to delete the file from disk

      Here is a reproducible test case:


      import java.io.*;

      public class BugReport
        {
        RandomAccessFile tmp_file = null;

        File file;

        public BugReport(String args[])
          {
          file = new File("foo");
          try
            {
            tmp_file = new RandomAccessFile(file, "rw");
            }
          catch (IOException e)
            {
            System.out.println("Error opening tmp file: " + e + ", exiting...");
            System.exit(0);
            }
          reopen_file();
          try
            {
            tmp_file.close();
            }
          catch (IOException e)
            {
            System.out.println("File close error: " + e + ", exiting...");
            System.exit(0);
            }
          if (!file.delete()) System.out.println("Error deleting file");
          }

        public void reopen_file()
          {
          String data;

          try
            {
            tmp_file = new RandomAccessFile(file, "rw");
            }
          catch (IOException e)
            {
            System.out.println("Error opening tmp file");
            return;
            }
          try
            {
            tmp_file.close();
            }
          catch (IOException e){}
          }

        public static void main(String args[])
          {
          new BugReport(args);
          }
        }

      To verify the bug, just create an ASCII file named "foo", add a few bytes
      to it and save it. Then, in the same directory, compile and run BugReport,
      the attached Java source file. On Win 95 an error message is printed, indicating
      that the file was not deleted; on Solaris, "foo" gets deleted, as it should.
      If you comment out the call to reopen_file(), I believe "foo" will get deleted.


      mei.chan@Corp 1997-04-24

      The problem turned out to be not a bug. We discovered a difference
      between Win95 and Solaris file system implementation.
      On Solaris you can File.delete() an open file.
      On Win95, you have to call tmp_file.close() before deleting the file.
      The Win95 OS keeps track of open files and would not allow you to delete the
      file until you explicitly close it.

      Here is the modified test case which would show the difference in behavior,
      ie. File.delete() on a file without closing it:

      import java.io.*;

      public class BugReport
        {
        RandomAccessFile tmp_file = null;

        File file;

        public BugReport(String args[])
          {
          file = new File("foo");
          try
            {
            tmp_file = new RandomAccessFile(file, "rw");
            System.out.println("created the file");
            }
          catch (IOException e)
            {
            System.out.println("Error opening tmp file: " + e + ", exiting...");
            System.exit(0);
            }

          if (file.exists())
              System.out.println("File exists");
          else
              System.out.println("File does not exist");

          if (!file.delete())
              System.out.println("Error deleting file");
          else System.out.println ("Deleted the file");
          }

        public static void main(String args[])
          {
          new BugReport(args);
          }
        }


      Results on Solaris:

      chicosun:/home/meiphen/java/progs/file_delete 78 % java BugReport
      created the file
      File exists
      Deleted the file


      Results on Win95:

      created the file
      File exists
      Error deleting the file


      Attachments

        Issue Links

          Activity

            People

              djbrown David Brown (Inactive)
              mchansunw Mei Chan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: