dainiusvaznys opened a new issue, #3975:
URL: https://github.com/apache/logging-log4j2/issues/3975

   ## Description
   
   [Issue #2380](https://github.com/apache/logging-log4j2/issues/2380) 
introduces generation of framework warning when last (implicit) parameter is a 
null `Throwable`.
   
   ## Configuration
   
   **Version:** 2.25.1
   
   **Operating system:** Windows 11
   
   **JDK:** Java HotSpot(TM) 64-Bit Server VM (build 25.461-b11, mixed mode)
   
   ## Logs
   
   ```
   2025-10-30T13:17:14,249 ERROR [main] MyTest {} - Execution completed with 
result invalid
   java.lang.RuntimeException: failed
        at ...
   
   2025-10-30T11:17:14.252438500Z main WARN found 1 argument placeholders, but 
provided 2 for pattern `Execution completed with result {}`
   2025-10-30T13:17:14,251 ERROR [main] MyTest  {} - Execution completed with 
result valid
   
   ```
   
   ## Reproduction
   Some libraries provide execution results in an 'Either' style of structure 
(e.g. `dev.failsafe.event.ExecutionCompletedEvent`) --result or an exception. 
Such cases could conveniently be logged like
   ```
   logger.error("Execution completed with result {}", outcome.result, 
outcome.failed);
   ```
   
   That is, if we have failure `Throwable` -- log its stack trace. But if it is 
`null` and the error is described in `.result` -- just log what we have. This 
used to work properly until a fix for #2380 introduces a warning (WARN found 1 
argument placeholders, but provided 2 for pattern), see sample test below and 
its output above.
   
   ```java
     record Result(
             String result,
             Throwable failed
     ) {}
   
     @Test
     void testLog4j() {
       var logger = 
org.apache.logging.log4j.LogManager.getLogger(NspMessageConsumerTest.class);
       var failedResult = new Result("invalid", new RuntimeException("failed"));
       logger.error("Execution completed with result {}", failedResult.result, 
failedResult.failed);
   
       var validResult = new Result("valid", null);
       logger.error("Execution completed with result {}", validResult.result, 
validResult.failed);
     }
   ```
   


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