Github user cakofony commented on a diff in the pull request:
https://github.com/apache/logging-log4j2/pull/205#discussion_r208699061
--- Diff:
log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
---
@@ -125,12 +123,23 @@ private void init(final String messagePattern, final
int argCount, final Object[
this.varargs = null;
this.messagePattern = messagePattern;
this.argCount = argCount;
- final int placeholderCount = count(messagePattern, indices);
- initThrowable(paramArray, argCount, placeholderCount);
- this.usedCount = Math.min(placeholderCount, argCount);
+
+ int usedParams = count(messagePattern, null);
+ if (usedParams < argCount && paramArray[argCount - 1] instanceof
Throwable) {
+ this.throwable = (Throwable) paramArray[argCount - 1];
+ } else {
+ this.throwable = null;
+ }
--- End diff --
I wonder if we should check `argCount > 0 && paramArray[argCount - 1]
instanceof Throwable` prior to invoking count? Could be worth a benchmark,
either way one iteration over a format string isn't very expensive.
---