Repository: logging-log4j2 Updated Branches: refs/heads/master 0fea0176d -> 6f6d95d3f
[LOG4J2-1990] ConcurrentModificationException logging a parameter of type Map. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6f6d95d3 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6f6d95d3 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6f6d95d3 Branch: refs/heads/master Commit: 6f6d95d3fcf2e17e66eb7763b6122adbe018f8be Parents: 0fea017 Author: Gary Gregory <[email protected]> Authored: Thu Jul 27 12:49:57 2017 -0700 Committer: Gary Gregory <[email protected]> Committed: Thu Jul 27 12:49:57 2017 -0700 ---------------------------------------------------------------------- .../log4j/core/impl/MutableLogEvent.java | 24 ++++++++++++++++---- src/changes/changes.xml | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6f6d95d3/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java index 56867b4..9f8a8b8 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java @@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.impl; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.util.Arrays; +import java.util.ConcurrentModificationException; import java.util.Map; import org.apache.logging.log4j.Level; @@ -32,6 +33,7 @@ import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.message.ReusableMessage; import org.apache.logging.log4j.message.SimpleMessage; +import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.util.StackLocatorUtil; import org.apache.logging.log4j.util.StringBuilders; import org.apache.logging.log4j.util.StringMap; @@ -207,11 +209,23 @@ public class MutableLogEvent implements LogEvent, ReusableMessage { public void setMessage(final Message msg) { if (msg instanceof ReusableMessage) { - final ReusableMessage reusable = (ReusableMessage) msg; - reusable.formatTo(getMessageTextForWriting()); - if (parameters != null) { - parameters = reusable.swapParameters(parameters); - parameterCount = reusable.getParameterCount(); + try { + final ReusableMessage reusable = (ReusableMessage) msg; + reusable.formatTo(getMessageTextForWriting()); + if (parameters != null) { + parameters = reusable.swapParameters(parameters); + parameterCount = reusable.getParameterCount(); + } + } catch (ConcurrentModificationException e) { + StringBuilder sb = getMessageTextForWriting(); + sb.append(getClass().getSimpleName()); + sb.append(": "); + sb.append(e.getClass().getName()); + sb.append(" in setting a "); + sb.append(msg.getClass().getSimpleName()); + sb.append("; format: "); + sb.append(msg.getFormat()); + StatusLogger.getLogger().warn(sb.toString(), e); } } else { // if the Message instance is reused, there is no point in freezing its message here http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6f6d95d3/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 0588360..211ffd1 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -43,6 +43,9 @@ <action issue="LOG4J2-1864" dev="mattsicker" type="add" due-to="Matthias Kappeller"> Support capped collections for MongoDb appender. </action> + <action issue="LOG4J2-1990" dev="ggregory" type="fix" due-to="Philippe Mouawad"> + ConcurrentModificationException logging a parameter of type Map. + </action> <action issue="LOG4J2-1977" dev="ggregory" type="fix" due-to="Jerry xnslong"> Consider the StringBuilder's capacity instead of content length when trimming. </action>
