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

Fix Resource Handling of `scalaStyleOnCompileConfig` in SparkBuild.scala

    XMLWordPrintableJSON

Details

    Description

      https://github.com/apache/spark/blob/e01ed0da22f24204fe23143032ff39be7f4b56af/project/SparkBuild.scala#L157-L173

       

      val scalaStyleOnCompileConfig: String = {
          val in = "scalastyle-config.xml"
          val out = "scalastyle-on-compile.generated.xml"
          val replacements = Map(
            """customId="println" level="error"""" -> """customId="println" level="warn""""
          )
          var contents = Source.fromFile(in).getLines.mkString("\n")
          for ((k, v) <- replacements) {
            require(contents.contains(k), s"Could not rewrite '$k' in original scalastyle config.")
            contents = contents.replace(k, v)
          }
          new PrintWriter(out) {
            write(contents)
            close()
          }
          out
        } 

      `Source.fromFile(in)` opens a `BufferedSource` resource handle, but it does not close it.

      Attachments

        Issue Links

          Activity

            People

              LuciferYang Yang Jie
              LuciferYang Yang Jie
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: