ppkarwasz commented on PR #3199:
URL: https://github.com/apache/logging-log4j2/pull/3199#issuecomment-2479855777

   > There are also users who have applications that don't need weak references 
here and would appreciate not risking having NPEs.
   
   There should be no such problem. The only place were weak references are 
used in this PR is the `WeakHashMap<MessageFactory, T extends ExtendedLogger>` 
used in `LoggerRegistry`.
   
   Loggers _could_ become unreachable if the message factory becomes 
unreachable. However the message factory never ceases to be reachable. In a 
typical `getLogger()` call, the message factory is last used on line 166 of 
`LoggerRegistry`:
   
   
https://github.com/apache/logging-log4j2/blob/8ee9387d9ec2063ab11f27eaa43e44a13f4c9935/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java#L533-L535
   
   
https://github.com/apache/logging-log4j2/blob/bf79552c902d6638415c78441ddf46771ad5a27b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerRegistry.java#L159-L170
   
   According to the [blog post shared by 
Volkan](https://shipilev.net/jvm/anatomy-quarks/8-local-var-reachability/) this 
means that the message factory will be reachable up to line 166. However, that 
line returns a `Logger` that has a reference to the message factory, so the 
message factory becomes reachable again. Worst case scenario, we might loose 
the entry in the `WeakHashMap`, but not the `Logger`.


-- 
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