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

java.io.FileOutputStream.write(int) doesn't throw exception if file doesnt exist

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description

      This bug was found by St.Petersburg Java SQE team (by Alexander Kuzmin).

      The java.io.FileOutputStream.write(int) does not work properly with IOException.
      If the file that FileOutputStream object connected to does not exist any more,
      FileOutputStream.write(int) does not throw IOException.


      _______________________Example ______________________________________
      import java.io.*;
      public class bug_test {
        public static void main( String argv[] ) {
         File f=null;
         FileOutputStream testfile=null;
       
          try {
           f=new File("to_delete"); //Create File object
          } catch (Throwable e )
             {System.out.println("Unable to create file.");
              return;
             }

          try {
           testfile=new FileOutputStream(f);//Create FileOutputSream object
          }
           catch (SecurityException e)
           {System.out.println("Unexpected SecurityException !");}
           catch (Exception e) //step Catch Exceptions
           {System.out.println(" Unexpected "+e+" thrown ");}

          try {
          testfile.write(100); // write something
          } catch (Throwable e ) {System.out.println("Enable to write !");}

          try {
           f.delete(); // Delete our file
          } catch (Throwable e) {System.out.println("Unable to delete file.");
              return; }

         
          try {
          testfile.write(100); // Our file does not exist
          } catch (IOException e)
            {System.out.println("OK ! IOException"); //will never get here
              return;
            }
            catch (Throwable e )
             {System.out.println("IOExeption not thrown ! But "+e);
              return;
             }

          System.out.println("IOException not thrown !");
        }
      }

      _____________________Output_________________________________________

      IOException not thrown !
      ____________________________________________________________________
        

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              mgorshen Mikhail Gorshenev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: