From 205b0d9f59c1e952810b2c571bc54c7ece1ff0ad Mon Sep 17 00:00:00 2001 From: Xinyuan Lin Date: Wed, 29 Jul 2026 05:09:24 -0700 Subject: [PATCH] refactor(config): replace the hand-rolled AuthConfig secret lock with lazy val --- .../texera/common/config/AuthConfig.scala | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/common/config/src/main/scala/org/apache/texera/common/config/AuthConfig.scala b/common/config/src/main/scala/org/apache/texera/common/config/AuthConfig.scala index 43e1409ecdd..abda5dff3da 100644 --- a/common/config/src/main/scala/org/apache/texera/common/config/AuthConfig.scala +++ b/common/config/src/main/scala/org/apache/texera/common/config/AuthConfig.scala @@ -28,20 +28,12 @@ object AuthConfig { // Read jwt Expiration time in minutes final val jwtExpirationMinutes: Int = conf.getInt("auth.jwt.expiration-in-minutes") - // For storing the generated/configured secret - @volatile private var secretKey: String = _ - - // Read JWT secret key with support for random generation - def jwtSecretKey: String = { - synchronized { - if (secretKey == null) { - secretKey = conf.getString("auth.jwt.256-bit-secret").toLowerCase() match { - case "random" => getRandomHexString - case key => key - } - } - } - secretKey + // Read JWT secret key with support for random generation. + // `lazy val` already compiles to a thread-safe, initialize-once accessor, so it + // replaces the hand-rolled @volatile + synchronized double-checked lock. + lazy val jwtSecretKey: String = conf.getString("auth.jwt.256-bit-secret").toLowerCase() match { + case "random" => getRandomHexString + case key => key } private def getRandomHexString: String = {