ppkarwasz commented on code in PR #2393:
URL: https://github.com/apache/logging-log4j2/pull/2393#discussion_r1536699879


##########
log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java:
##########
@@ -240,12 +244,17 @@ static void formatMessage(
             return;
         }
 
-        // Fail if there are insufficient arguments
-        if (analysis.placeholderCount > args.length) {
-            final String message = String.format(
-                    "found %d argument placeholders, but provided %d for 
pattern `%s`",
-                    analysis.placeholderCount, args.length, pattern);
-            throw new IllegalArgumentException(message);
+        // #2380: check if the count of placeholder is not equal to the count 
of arguments
+        if (analysis.placeholderCount != argCount) {
+            final int realArgCount = args.length;
+            final int noThrowableArgCount = realArgCount - ((args[realArgCount 
- 1] instanceof Throwable) ? 1 : 0);

Review Comment:
   ```suggestion
               final int noThrowableArgCount = realArgCount - ((args[argCount - 
1] instanceof Throwable) ? 1 : 0);
   ```
   
   Use `argCount` instead of `args.length`: the array can have an arbitrary 
length (it can be reused by multiple messages), that is why the method accepts 
`argCount` as argument.



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

Reply via email to