From 39717f1e444f03e395efa9042e2aae006673e48d Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 28 Jan 2022 16:32:24 +0100 Subject: [PATCH 1/2] Close Files.lines stream Fixes #14376 --- compiler/test/dotty/tools/utils.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/utils.scala b/compiler/test/dotty/tools/utils.scala index c70dbf3456cb..f1faa77b1f48 100644 --- a/compiler/test/dotty/tools/utils.scala +++ b/compiler/test/dotty/tools/utils.scala @@ -47,7 +47,11 @@ def assertThrows[T <: Throwable: ClassTag](p: T => Boolean)(body: => Any): Unit end assertThrows def toolArgsFor(files: List[JPath], charset: Charset = UTF_8): List[String] = - files.flatMap(path => toolArgsParse(Files.lines(path, charset).limit(10).toScala(List))) + files.flatMap(path => toolArgsParse { + val stream = Files.lines(path, charset) + try stream.limit(10).toScala(List) + finally stream.close() + }) // Inspect the first 10 of the given lines for compiler options of the form // `// scalac: args`, `/* scalac: args`, ` * scalac: args`. From b022b55e01735b1e24dd7401c8efbe7817cfc576 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 28 Jan 2022 16:42:23 +0100 Subject: [PATCH 2/2] Use `Using.resource` --- compiler/test/dotty/tools/utils.scala | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/compiler/test/dotty/tools/utils.scala b/compiler/test/dotty/tools/utils.scala index f1faa77b1f48..388715f45cc2 100644 --- a/compiler/test/dotty/tools/utils.scala +++ b/compiler/test/dotty/tools/utils.scala @@ -47,11 +47,7 @@ def assertThrows[T <: Throwable: ClassTag](p: T => Boolean)(body: => Any): Unit end assertThrows def toolArgsFor(files: List[JPath], charset: Charset = UTF_8): List[String] = - files.flatMap(path => toolArgsParse { - val stream = Files.lines(path, charset) - try stream.limit(10).toScala(List) - finally stream.close() - }) + files.flatMap(path => toolArgsParse(resource(Files.lines(path, charset))(_.limit(10).toScala(List)))) // Inspect the first 10 of the given lines for compiler options of the form // `// scalac: args`, `/* scalac: args`, ` * scalac: args`.