From f03320047e69f966e328435f48aafeb1c57029cc Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Mon, 25 Sep 2023 17:40:12 +0200 Subject: [PATCH 1/2] Keep logger names in hash set Previously, the list of logger names that have been created in a given context with Log4J was being kept in a `Vector`. As a result, subsequent calls to `logger` on a `Log4JLoggerContext` with the same logger name would introduce duplicates in the list. Note that Log4J's logger configuration would not allow duplicates, and only one configuration object for a given logger name will exist. The duplicates in the list of logger names are therefore unnecessary. With this patch, the logger names will be kept in a `HashSet`. Since the logger names are only used to remove the logger configurations after the logger context is closed, and the logger configurations contain no duplicates, removing duplicate logger names should not cause any issue. --- .../util-logging/src/main/scala/sbt/util/LoggerContext.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/util-logging/src/main/scala/sbt/util/LoggerContext.scala b/internal/util-logging/src/main/scala/sbt/util/LoggerContext.scala index c887c786f..58aa5107a 100644 --- a/internal/util-logging/src/main/scala/sbt/util/LoggerContext.scala +++ b/internal/util-logging/src/main/scala/sbt/util/LoggerContext.scala @@ -46,7 +46,7 @@ object LoggerContext { case a: AbstractConfiguration => a case _ => throw new IllegalStateException("") } - val loggers = new java.util.Vector[String] + val loggers = new java.util.HashSet[String] private[this] val closed = new AtomicBoolean(false) override def logger( name: String, From d27a1a4ebbb8a52c4800e06dd645ba8dc8d371b5 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Wed, 11 Oct 2023 20:59:19 +0200 Subject: [PATCH 2/2] Add MiMa exclusion Changing the return type of is fine because this symbol is private and internal to sbt. --- build.sbt | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sbt b/build.sbt index bba828f2a..446206ea1 100644 --- a/build.sbt +++ b/build.sbt @@ -428,6 +428,7 @@ lazy val utilLogging = (project in file("internal") / "util-logging") exclude[MissingTypesProblem]("sbt.internal.util.ConsoleAppender"), exclude[MissingTypesProblem]("sbt.internal.util.BufferedAppender"), exclude[MissingClassProblem]("sbt.internal.util.Terminal$BlockingInputStream$"), + exclude[IncompatibleResultTypeProblem]("sbt.util.LoggerContext#Log4JLoggerContext.loggers"), ), ) .configure(addSbtIO)