Skip to content

Commit e20198f

Browse files
committed
ListAppender: Synchronize on list while iterating
* Returned snapshots no longer require an unmodifiable view
1 parent 9b9a0d4 commit e20198f

File tree

1 file changed

+12
-6
lines changed
  • log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/appender

1 file changed

+12
-6
lines changed

log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/appender/ListAppender.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,18 @@ public ListAppender clear() {
195195
return this;
196196
}
197197

198-
/** Returns an immutable snapshot of captured log events */
198+
/** Returns a snapshot of captured log events */
199199
public List<LogEvent> getEvents() {
200-
return Collections.<LogEvent>unmodifiableList(new ArrayList<>(events));
200+
synchronized (events) {
201+
return new ArrayList<>(events);
202+
}
201203
}
202204

203-
/** Returns an immutable snapshot of captured messages */
205+
/** Returns a snapshot of captured messages */
204206
public List<String> getMessages() {
205-
return Collections.<String>unmodifiableList(new ArrayList<>(messages));
207+
synchronized (messages) {
208+
return new ArrayList<>(messages);
209+
}
206210
}
207211

208212
/**
@@ -215,9 +219,11 @@ public List<String> getMessages(final int minSize, final long timeout, final Tim
215219
return getMessages();
216220
}
217221

218-
/** Returns an immutable snapshot of captured data */
222+
/** Returns a snapshot of captured data */
219223
public List<byte[]> getData() {
220-
return Collections.<byte[]>unmodifiableList(new ArrayList<>(data));
224+
synchronized (data) {
225+
return new ArrayList<>(data);
226+
}
221227
}
222228

223229
public static ListAppender createAppender(

0 commit comments

Comments
 (0)