From 23ca0d5705b2b9c6efd9143a06722fc42a2f94db Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Fri, 25 Sep 2020 11:20:32 +0200 Subject: [PATCH] Close classpath directory after listing A `newDirectoryStream` must be closed after reading. We can do that immediately because we're sorting the list so we have to consume the entire stream anyway. --- .../scala/com/typesafe/tools/mima/core/ClassPath.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/com/typesafe/tools/mima/core/ClassPath.scala b/core/src/main/scala/com/typesafe/tools/mima/core/ClassPath.scala index 85591e5b..139844bb 100644 --- a/core/src/main/scala/com/typesafe/tools/mima/core/ClassPath.scala +++ b/core/src/main/scala/com/typesafe/tools/mima/core/ClassPath.scala @@ -47,7 +47,12 @@ private[mima] object ClassPath { private def javaBootCp = expandCp(System.getProperty("sun.boot.class.path", "")) import scala.collection.JavaConverters._ - private def list(p: Path) = Files.newDirectoryStream(p).asScala.toStream.sortBy(_.toString) + private def list(p: Path) = { + val stream = Files.newDirectoryStream(p) + val list = stream.asScala.toStream.sortBy(_.toString) + stream.close() + list + } private def listDir(p: Path) = if (Files.isDirectory(p)) list(p) else Stream.empty private def readLink(p: Path) = if (Files.isSymbolicLink(p)) Files.readSymbolicLink(p) else p private def rootPath(p: Path) = FileSystems.newFileSystem(p, null).getPath("/")