Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.Serializable;
import java.util.concurrent.ConcurrentSkipListSet;

import static io.microsphere.collection.SetUtils.newConcurrentSkipListSet;
import static io.microsphere.logging.log4j2.LogEventComparator.INSTANCE;
import static io.microsphere.logging.log4j2.util.Log4j2Utils.findAppender;

Expand All @@ -42,7 +43,7 @@ public class InMemoryAppender extends AbstractLifeCycle implements Appender {
*/
public static final String NAME = "InMemory";

private final ConcurrentSkipListSet<LogEvent> logEvents = new ConcurrentSkipListSet<>(INSTANCE);
private final ConcurrentSkipListSet<LogEvent> logEvents = newConcurrentSkipListSet(INSTANCE);

/**
* Appends the given {@link LogEvent} to the in-memory collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.apache.logging.log4j.core.layout.ByteBufferDestination;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import static io.microsphere.collection.MapUtils.newHashMap;
import static io.microsphere.logging.log4j2.appender.InMemoryAppender.NAME;
import static org.apache.logging.log4j.core.layout.PatternLayout.newBuilder;

Expand Down Expand Up @@ -66,7 +66,7 @@ public SmartFileAppenderLayout(LoggerContext context) {
}

private Map<String, Layout> initDelegatingLayouts(LoggerContext context) {
Map<String, Layout> delegatingLayouts = new HashMap<>();
Map<String, Layout> delegatingLayouts = newHashMap();
for (Logger logger : context.getLoggers()) {
String loggerName = logger.getName();
Layout layout = selectLayout(logger);
Expand All @@ -91,7 +91,7 @@ private Appender selectAppender(Logger logger) {

private Appender selectAppender(Logger logger, Class<? extends Appender> appenderClass) {
Appender targetAppender = null;
Map<String, Appender> appendersMap = new HashMap<>(logger.getAppenders());
Map<String, Appender> appendersMap = newHashMap(logger.getAppenders());
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SmartFileAppenderLayout#selectAppender(...) previously relied on new HashMap<>(logger.getAppenders()) to always create a defensive copy before remove(NAME). Can you confirm MapUtils.newHashMap(map) also always returns a new mutable copy (never the same instance or a view), otherwise this would mutate the logger's original appender map?

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

appendersMap.remove(NAME);
if (appendersMap.isEmpty()) {
Logger parentLogger = logger.getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import org.apache.logging.log4j.message.SimpleMessage;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static io.microsphere.collection.ListUtils.newArrayList;
import static io.microsphere.logging.log4j2.appender.InMemoryAppender.NAME;
import static io.microsphere.logging.log4j2.appender.InMemoryAppender.findInMemoryAppender;
import static java.lang.Thread.sleep;
Expand Down Expand Up @@ -111,7 +111,7 @@ private static LogEvent newEvent(String message) throws InterruptedException {
}

private static class CollectingAppender implements Appender {
private final List<LogEvent> events = new ArrayList<>();
private final List<LogEvent> events = newArrayList();

@Override
public void append(LogEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import org.junit.jupiter.api.Test;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static io.microsphere.collection.ListUtils.newArrayList;
import static io.microsphere.logging.log4j2.util.Log4j2Utils.addAppender;
import static io.microsphere.logging.log4j2.util.Log4j2Utils.findAppender;
import static io.microsphere.logging.log4j2.util.Log4j2Utils.getLevel;
Expand Down Expand Up @@ -172,7 +172,7 @@ void shouldCoverDoInLoggerAndFindAppender() {
@Test
void shouldCoverAddRemoveAppenderStaticHelpers() {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
List<Logger> targets = new ArrayList<>();
List<Logger> targets = newArrayList();
targets.add(context.getRootLogger());

TestAppender appender = new TestAppender("helperAppender");
Expand All @@ -197,7 +197,7 @@ void shouldCoverAddRemoveAppenderStaticHelpers() {
@Test
void shouldCoverAddRemoveAppenderNullGuardsAndLifecycleBranches() {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
List<Logger> targets = new ArrayList<>();
List<Logger> targets = newArrayList();
targets.add(context.getRootLogger());

// null guard branches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import java.util.LinkedList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.logging.LoggingMXBean;

import static io.microsphere.collection.ListUtils.newLinkedList;
import static io.microsphere.lang.function.ThrowableSupplier.execute;
import static io.microsphere.logging.LoggerFactory.getLogger;
import static io.microsphere.logging.LoggingUtils.loadAll;
Expand Down Expand Up @@ -75,7 +75,7 @@ public static List<ObjectInstance> registerAll() {
*/
@Nonnull
public static List<ObjectInstance> registerAll(ClassLoader classLoader) {
List<ObjectInstance> instances = new LinkedList<>();
List<ObjectInstance> instances = newLinkedList();
Iterable<Logging> loggings = loadAll(classLoader);
for (Logging logging : loggings) {
ObjectInstance instance = register(logging);
Expand Down
2 changes: 1 addition & 1 deletion microsphere-logging-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<description>Microsphere Logging Parent</description>

<properties>
<microsphere-java.version>0.3.5</microsphere-java.version>
<microsphere-java.version>0.3.6</microsphere-java.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;

import java.util.ArrayList;
import java.util.List;

import static io.microsphere.collection.ListUtils.newArrayList;

/**
* The facade class of {@link ClassTemplateInvocationContext} and {@link TestTemplateInvocationContext} to set the
* logging level.
Expand Down Expand Up @@ -96,7 +97,7 @@ public String getDisplayName(int invocationIndex) {
*/
@Override
public List<Extension> getAdditionalExtensions() {
List<Extension> extensions = new ArrayList<>(this.isClassTemplate ? 2 : 1);
List<Extension> extensions = newArrayList(this.isClassTemplate ? 2 : 1);
extensions.add(new LoggingLevelCallback(this.loggins, this.loggerName, this.level));
if (this.isClassTemplate) {
extensions.add(new LoggingLevelParameterResolver(this.level, this.index));
Expand Down
Loading