ppkarwasz commented on issue #3284: URL: https://github.com/apache/logging-log4j2/issues/3284#issuecomment-2553195806
@SweetWuXiaoMei, > https://github.com/apache/logging-log4j2/blob/e65538dc75b52fd2f3e49d4ab5d7b40b376abb89/log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/InternalLoggerRegistry.java#L148-L154 > > This code snippet looks like a bug.If it is created for the first time, the `loggerRefByName` variable is `null`. Because `loggerRefByNameByMessageFactory.computeIfAbsent` will return `null`. I can fix this bug if needed. You are probably confusing [`Map.putIfAbsent()`](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#putIfAbsent-K-V-) with [`Map.computeIfAbsent()`](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#computeIfAbsent-K-java.util.function.Function-): * `putIfAbsent()` returns the **previous** value associated to a given key, so it can return `null`. * `computeIfAbsent()` returns the **current** value associated to a given key (existing or computed). It can only return `null` if the lambda returns `null`. Since `() -> new HashMap<>()` **never** returns `null`, neither does `computeIfAbsent()`. The reason why `null` is returned in your test case is that your are **mocking** the `loggerRefByNameByMessageFactory` map using JMockit. Every method of a mocked object usually returns `null` and I confirmed that this is your case by running your ServiceComb test in a debugger. I have no experience with JMockit, so I don't know how to configure it to leave the Log4j classes alone. You should probably ask the JMockit developers directly. -- 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: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org