Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-17573

The FileInputStream may be uncloseed when some exceptions occurs

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Trivial
    • Resolution: Not A Problem
    • 2.0.0
    • None
    • Spark Core
    • Important

    Description

      I think that the InputStream may never be closed when some exceptions occur, we should surround this with try catch.

       private def addFilesToZipStream(parent: String, source: File, output: ZipOutputStream): Unit = {
          if (source.isDirectory()) {
            output.putNextEntry(new ZipEntry(parent + source.getName()))
            for (file <- source.listFiles()) {
              addFilesToZipStream(parent + source.getName() + File.separator, file, output)
            }
          } else {
            val in = new FileInputStream(source)
            output.putNextEntry(new ZipEntry(parent + source.getName()))
            val buf = new Array[Byte](8192)
            var n = 0
            while (n != -1) {
              n = in.read(buf)
              if (n != -1) {
                output.write(buf, 0, n)
              }
            }
            output.closeEntry()
            in.close()
          }
        }
      some code in TestUtils.scala
       val in = new FileInputStream(file)
            ByteStreams.copy(in, jarStream)
           in.close()
      
      some code in IvyTestUtils.scala
         val in = new FileInputStream(file._2)
            ByteStreams.copy(in, jarStream)
            in.close()
      
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            codlife Jianfei Wang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: