From 616d4232393471299de5894daaeb91ae5f6e295b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Fri, 15 Sep 2023 09:37:29 +0200 Subject: [PATCH] bugfix/Close streams at the function gitCommit and use lazy val instead of def --- src/main/scala/code/snippet/ApiExplorer.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/scala/code/snippet/ApiExplorer.scala b/src/main/scala/code/snippet/ApiExplorer.scala index 7c0dc5d6..eac5446c 100644 --- a/src/main/scala/code/snippet/ApiExplorer.scala +++ b/src/main/scala/code/snippet/ApiExplorer.scala @@ -1908,13 +1908,18 @@ WIP to add comments on resource docs. This code copied from Sofit. /* Return the git commit. If we can't for some reason (not a git root etc) then log and return "" */ - def gitCommit : String = { + lazy val gitCommit : String = { val commit = try { val properties = new java.util.Properties() logger.debug("Before getResourceAsStream git.properties") - properties.load(getClass().getClassLoader().getResourceAsStream("git.properties")) - logger.debug("Before get Property git.commit.id") - properties.getProperty("git.commit.id", "") + val stream = getClass().getClassLoader().getResourceAsStream("git.properties") + try { + properties.load(stream) + logger.debug("Before get Property git.commit.id") + properties.getProperty("git.commit.id", "") + } finally { + stream.close() + } } catch { case e : Throwable => { logger.warn("gitCommit says: Could not return git commit. Does resources/git.properties exist?")