[ 
https://issues.apache.org/jira/browse/LOG4J2-1990?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16102888#comment-16102888
 ] 

Gary Gregory edited comment on LOG4J2-1990 at 7/27/17 7:55 AM:
---------------------------------------------------------------

You're right, synchronizing will not help. 

Why won't wrapping help? m = new HashMap(); m.addAll(...) I guess that you 
could get a CME during the copying which needs to iterate... 

Maybe we need to catch CME and just log that we cannot get the next element:

{noformat}
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
 
b/log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
index 79c447a..4aa8c62 100644
--- 
a/log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
+++ 
b/log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
@@ -19,11 +19,13 @@
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.ConcurrentModificationException;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.StringBuilderFormattable;
 
 /**
@@ -566,18 +568,22 @@
             final Map<?, ?> oMap = (Map<?, ?>) o;
             str.append('{');
             boolean isFirst = true;
-            for (final Object o1 : oMap.entrySet()) {
-                final Map.Entry<?, ?> current = (Map.Entry<?, ?>) o1;
-                if (isFirst) {
-                    isFirst = false;
-                } else {
-                    str.append(", ");
+            try {
+                for (final Object o1 : oMap.entrySet()) {
+                    final Map.Entry<?, ?> current = (Map.Entry<?, ?>) o1;
+                    if (isFirst) {
+                        isFirst = false;
+                    } else {
+                        str.append(", ");
+                    }
+                    final Object key = current.getKey();
+                    final Object value = current.getValue();
+                    recursiveDeepToString(key, str, new HashSet<>(dejaVu));
+                    str.append('=');
+                    recursiveDeepToString(value, str, new HashSet<>(dejaVu));
                 }
-                final Object key = current.getKey();
-                final Object value = current.getValue();
-                recursiveDeepToString(key, str, new HashSet<>(dejaVu));
-                str.append('=');
-                recursiveDeepToString(value, str, new HashSet<>(dejaVu));
+            } catch (ConcurrentModificationException e) {
+                StatusLogger.getLogger().warn("ConcurrentModificationException 
logging a Map", e);
             }
             str.append('}');
         }
@@ -596,13 +602,17 @@
             final Collection<?> oCol = (Collection<?>) o;
             str.append('[');
             boolean isFirst = true;
-            for (final Object anOCol : oCol) {
-                if (isFirst) {
-                    isFirst = false;
-                } else {
-                    str.append(", ");
+            try {
+                for (final Object anOCol : oCol) {
+                    if (isFirst) {
+                        isFirst = false;
+                    } else {
+                        str.append(", ");
+                    }
+                    recursiveDeepToString(anOCol, str, new HashSet<>(dejaVu));
                 }
-                recursiveDeepToString(anOCol, str, new HashSet<>(dejaVu));
+            } catch (ConcurrentModificationException e) {
+                StatusLogger.getLogger().warn("ConcurrentModificationException 
logging  a Collection", e);
             }
             str.append(']');
         }
{noformat}

and maybe even put something in the string we're building...
?


was (Author: garydgregory):
You're right, synchronizing will not help. 

Why won't wrapping help? m = new HashMap(); m.addAll(...) I guess that you 
could get a CME during the copying which needs to iterate... 

Maybe we need to catch CME and just log that we cannot get the next element:

{noformat}
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
 
b/log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
index 79c447a..4aa8c62 100644
--- 
a/log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
+++ 
b/log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
@@ -19,11 +19,13 @@
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.ConcurrentModificationException;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.StringBuilderFormattable;
 
 /**
@@ -566,18 +568,22 @@
             final Map<?, ?> oMap = (Map<?, ?>) o;
             str.append('{');
             boolean isFirst = true;
-            for (final Object o1 : oMap.entrySet()) {
-                final Map.Entry<?, ?> current = (Map.Entry<?, ?>) o1;
-                if (isFirst) {
-                    isFirst = false;
-                } else {
-                    str.append(", ");
+            try {
+                for (final Object o1 : oMap.entrySet()) {
+                    final Map.Entry<?, ?> current = (Map.Entry<?, ?>) o1;
+                    if (isFirst) {
+                        isFirst = false;
+                    } else {
+                        str.append(", ");
+                    }
+                    final Object key = current.getKey();
+                    final Object value = current.getValue();
+                    recursiveDeepToString(key, str, new HashSet<>(dejaVu));
+                    str.append('=');
+                    recursiveDeepToString(value, str, new HashSet<>(dejaVu));
                 }
-                final Object key = current.getKey();
-                final Object value = current.getValue();
-                recursiveDeepToString(key, str, new HashSet<>(dejaVu));
-                str.append('=');
-                recursiveDeepToString(value, str, new HashSet<>(dejaVu));
+            } catch (ConcurrentModificationException e) {
+                StatusLogger.getLogger().warn("ConcurrentModificationException 
logging a Map", e);
             }
             str.append('}');
         }
@@ -596,13 +602,17 @@
             final Collection<?> oCol = (Collection<?>) o;
             str.append('[');
             boolean isFirst = true;
-            for (final Object anOCol : oCol) {
-                if (isFirst) {
-                    isFirst = false;
-                } else {
-                    str.append(", ");
+            try {
+                for (final Object anOCol : oCol) {
+                    if (isFirst) {
+                        isFirst = false;
+                    } else {
+                        str.append(", ");
+                    }
+                    recursiveDeepToString(anOCol, str, new HashSet<>(dejaVu));
                 }
-                recursiveDeepToString(anOCol, str, new HashSet<>(dejaVu));
+            } catch (ConcurrentModificationException e) {
+                StatusLogger.getLogger().warn("ConcurrentModificationException 
logging  a Collection", e);
             }
             str.append(']');
         }
{noformat}

?

> ConcurrentModificationException logging a parameter of type Map 
> ----------------------------------------------------------------
>
>                 Key: LOG4J2-1990
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1990
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.8.2
>            Reporter: Philippe Mouawad
>         Attachments: LOG4J2-1990.patch
>
>
> Hello,
> Working with current JMeter trunk and:
> *  attached test plan 
> * org.apache.jmeter.protocol.http.control.CacheManager level set to debug in 
> log4j2.xml in bin folder
> I get:
> {code:none}
> java.util.concurrent.ExecutionException: 
> java.util.ConcurrentModificationException
>       at java.util.concurrent.FutureTask.report(FutureTask.java:122) 
> ~[?:1.8.0_121]
>       at java.util.concurrent.FutureTask.get(FutureTask.java:192) 
> ~[?:1.8.0_121]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.downloadPageResources(HTTPSamplerBase.java:1349)
>  [ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.resultProcessing(HTTPSamplerBase.java:1657)
>  [ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl.resultProcessing(HTTPAbstractImpl.java:519)
>  [ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:534)
>  [ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
>  [ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1189)
>  [ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1178)
>  [ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:500)
>  [ApacheJMeter_core.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:425) 
> [ApacheJMeter_core.jar:3.3-SNAPSHOT.20170724]
>       at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:254) 
> [ApacheJMeter_core.jar:3.3-SNAPSHOT.20170724]
>       at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
> Caused by: java.util.ConcurrentModificationException
>       at 
> org.apache.commons.collections.map.AbstractLinkedMap$LinkIterator.nextEntry(AbstractLinkedMap.java:560)
>  ~[commons-collections-3.2.2.jar:3.2.2]
>       at 
> org.apache.commons.collections.map.AbstractLinkedMap$EntrySetIterator.next(AbstractLinkedMap.java:428)
>  ~[commons-collections-3.2.2.jar:3.2.2]
>       at 
> org.apache.logging.log4j.message.ParameterFormatter.appendMap(ParameterFormatter.java:569)
>  ~[log4j-api-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.message.ParameterFormatter.appendPotentiallyRecursiveValue(ParameterFormatter.java:505)
>  ~[log4j-api-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.message.ParameterFormatter.recursiveDeepToString(ParameterFormatter.java:432)
>  ~[log4j-api-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.message.ParameterFormatter.formatMessage2(ParameterFormatter.java:189)
>  ~[log4j-api-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.message.ReusableParameterizedMessage.formatTo(ReusableParameterizedMessage.java:313)
>  ~[log4j-api-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.core.impl.MutableLogEvent.setMessage(MutableLogEvent.java:214)
>  ~[log4j-core-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.core.impl.ReusableLogEventFactory.createEvent(ReusableLogEventFactory.java:81)
>  ~[log4j-core-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:401) 
> [log4j-core-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
>  [log4j-core-2.8.2.jar:2.8.2]
>       at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146) 
> [log4j-core-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2091)
>  [log4j-api-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2005)
>  [log4j-api-2.8.2.jar:2.8.2]
>       at 
> org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1876)
>  [log4j-api-2.8.2.jar:2.8.2]
>       at org.apache.logging.slf4j.Log4jLogger.debug(Log4jLogger.java:124) 
> [log4j-slf4j-impl-2.8.2.jar:2.8.2]
>       at 
> org.apache.jmeter.protocol.http.control.CacheManager.getEntry(CacheManager.java:501)
>  ~[ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.control.CacheManager.inCache(CacheManager.java:431)
>  ~[ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:443)
>  ~[ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
>  ~[ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase$ASyncSample.call(HTTPSamplerBase.java:2031)
>  ~[ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at 
> org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase$ASyncSample.call(HTTPSamplerBase.java:1)
>  ~[ApacheJMeter_http.jar:3.3-SNAPSHOT.20170724]
>       at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
> ~[?:1.8.0_121]
>       at 
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
> ~[?:1.8.0_121]
>       at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
> ~[?:1.8.0_121]
>       at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>  ~[?:1.8.0_121]
>       at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>  ~[?:1.8.0_121]
>       ... 1 more
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to