title: Function returns an empty List in Spark
body: <p>Below is code for getting list of file Names in a zipped file</p>
  
  <pre><code>def getListOfFilesInRepo(zipFileRDD : RDD[(String,PortableDataStream)]) : (List[String]) = {
      val zipInputStream = zipFileRDD.values.map(x =&gt; new ZipInputStream(x.open))
      val filesInZip =  new ArrayBuffer[String]()
      var ze : Option[ZipEntry] = None
      zipInputStream.foreach(stream =&gt;{
        do{
          ze = Option(stream.getNextEntry);
          ze.foreach{ze =&gt;
            if(ze.getName.endsWith("java") &amp;&amp; !ze.isDirectory()){
              var fileName:String = ze.getName.substring(ze.getName.lastIndexOf("/")+1,ze.getName.indexOf(".java"))
              filesInZip += fileName
            }
          }
          stream.closeEntry()
        } while(ze.isDefined)
        println(filesInZip.toList.length) // print 889 (correct)
      })
      println(filesInZip.toList.length) // print 0 (WHY..?)
      (filesInZip.toList)
    }
  </code></pre>
  
  <p>I execute above code in the following manner :</p>
  
  <pre><code>scala&gt; val zipFileRDD = sc.binaryFiles("./handsOn/repo~apache~storm~14135470~false~Java~master~2210.zip")
  zipFileRDD: org.apache.spark.rdd.RDD[(String, org.apache.spark.input.PortableDataStream)] = ./handsOn/repo~apache~storm~14135470~false~Java~master~2210.zip BinaryFileRDD[17] at binaryFiles at &lt;console&gt;:25
  
  scala&gt; getListOfFilesInRepo(zipRDD)
  889
  0
  res12: List[String] = List()
  </code></pre>
  
  <p>Why i am not getting 889 and instead getting 0?</p>