From 644857ba800c26a45676902a906cbd37792367f7 Mon Sep 17 00:00:00 2001 From: coofee Date: Fri, 17 May 2019 11:20:38 +0800 Subject: [PATCH 1/2] fix: LoggerPrinter ConcurrentModificationException MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LoggerPrinter will throw java.util.ConcurrentModificationException when LoggerPrinter.log() and LoggerPrinter.addAdapter()/LoggerPrinter.clearLogAdapters() invoke in different thread at the same time。 --- logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java b/logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java index bdd25530..c4c9a556 100644 --- a/logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java +++ b/logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java @@ -11,6 +11,7 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; @@ -40,7 +41,7 @@ class LoggerPrinter implements Printer { */ private final ThreadLocal localTag = new ThreadLocal<>(); - private final List logAdapters = new ArrayList<>(); + private final List logAdapters = new CopyOnWriteArrayList<>(); @Override public Printer t(String tag) { if (tag != null) { From 463456faddd9ae4fc156eee86ff9e27c825ada7b Mon Sep 17 00:00:00 2001 From: coofee Date: Fri, 17 May 2019 11:37:32 +0800 Subject: [PATCH 2/2] refactor: remove unused imports. remove unused import java.util.ArrayList --- logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java b/logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java index c4c9a556..1bc65b0d 100644 --- a/logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java +++ b/logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java @@ -9,7 +9,6 @@ import java.io.StringReader; import java.io.StringWriter; -import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList;