aglinxinyuan opened a new issue, #7039:
URL: https://github.com/apache/texera/issues/7039

   ### Task Summary
   
   `AuthConfig.jwtSecretKey` hand-rolls a double-checked-locking lazy 
initializer — a `@volatile var`, a null check and a `synchronized` block — to 
compute a value once:
   
   ```scala
   @volatile private var secretKey: String = _
   
   def jwtSecretKey: String = {
     synchronized {
       if (secretKey == null) {
         secretKey = conf.getString("auth.jwt.256-bit-secret").toLowerCase() 
match {
           case "random" => getRandomHexString
           case key      => key
         }
       }
     }
     secretKey
   }
   ```
   
   Scala's `lazy val` is exactly this pattern, generated by the compiler: 
initialize-once, thread-safe, and — like the hand-rolled version — it retries 
on the next access if the initializer throws, since the initialized bit is only 
set on success.
   
   Replacing it removes the mutable field, the null sentinel and the explicit 
lock, leaving the intent visible:
   
   ```scala
   lazy val jwtSecretKey: String = 
conf.getString("auth.jwt.256-bit-secret").toLowerCase() match {
     case "random" => getRandomHexString
     case key      => key
   }
   ```
   
   The single caller (`JwtAuth.TOKEN_SECRET`) is unchanged, since `def` and 
`lazy val` are indistinguishable at the call site.
   
   −14 lines, +6.
   
   ### Task Type
   
   - [x] Refactor / Cleanup
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to