Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-4917

FB - FileUtils.java - may fail to clean up streams

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 2.9.0
    • None
    • None

    Description

      Resolve FindBugs issues in FileUtils.java

      In copyAction method

      Before

      FileInputStream istream = new FileInputStream(srcFile);
      FileOutputStream ostream = new FileOutputStream(destFile);
      FileChannel input = istream.getChannel();
      FileChannel output = ostream.getChannel();
      
      try {
          input.transferTo(0, input.size(), output);
      } finally {
          istream.close();
          ostream.close();
          input.close();
          output.close();
      }
      

      After

      FileInputStream istream = new FileInputStream(srcFile);
      try {
          FileOutputStream ostream = new FileOutputStream(destFile);
          FileChannel input = istream.getChannel();
          FileChannel output = ostream.getChannel();		
          try {
              input.transferTo(0, input.size(), output);
          } finally {
              ostream.close();
              input.close();
              output.close();
          }
      } finally {
          istream.close();
      }
      

      In write method

      Before

      ByteArrayInputStream in = new ByteArrayInputStream(rawData);
      FileOutputStream out = new FileOutputStream(filename, append);
      byte buff[] = new byte[rawData.length];
      in.read(buff, 0, buff.length);
      out.write(buff, 0, rawData.length);
      out.flush();
      out.close();
      

      After

      ByteArrayInputStream in = new ByteArrayInputStream(rawData);
      FileOutputStream out = new FileOutputStream(filename, append);
      try {
          byte buff[] = new byte[rawData.length];
          in.read(buff, 0, buff.length);
          out.write(buff, 0, rawData.length);
          out.flush();
      } finally {
          out.close();
      }
      

      Attachments

        Issue Links

          Activity

            People

              iclelland Ian Clelland
              dinglemouse Peter
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: