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

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

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Not verified

      Backports

        Description

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

        The java.io.FileOutputStream.write(byte[],int,int) does not work properly
        with IOException.
        If the file that FileOutputStream object connected to doesn't exist any more,
        FileOutputStream.write(byte[],int,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;
           byte b[]={'1','2','3','4','5'};

            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(b,0,b.length); // 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(b,0,b.length); // 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:
                gbrachasunw Gilad Bracha (Inactive)
                Reporter:
                mgorshen Mikhail Gorshenev (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: