gnodet-bot commented on code in PR #13832:
URL: https://github.com/apache/maven/pull/13832#discussion_r4535415197
##########
impl/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java:
##########
@@ -67,10 +67,16 @@ public class InjectorImpl implements Injector {
private final Set<String> loadedUrls = new HashSet<>();
private final ThreadLocal<Set<Key<?>>> resolutionStack = new
ThreadLocal<>();
+ private final Consumer<String> dumpSink;
private final InjectorDiagnostics diagnostics = new
InjectorDiagnostics(this, bindings, scopes);
private int registrationDepth;
public InjectorImpl() {
+ this(System.out::println);
Review Comment:
⚠️ **System.out default sink**: the no-arg constructor delegates to
`System.out::println`. Any code path that calls `new InjectorImpl()` (including
production code currently using it) will silently write DI diagnostics to
stdout instead of the Maven log sink. Consider defaulting to a no-op sink — or
at minimum a `LoggerFactory.getLogger(InjectorImpl.class)::debug` — so callers
that don't need diagnostics don't accidentally produce output.
##########
impl/maven-logging-slf4j/src/main/java/org/apache/maven/logging/slf4j/MavenSimpleLogger.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.logging.slf4j;
+
+import java.util.Arrays;
+import java.util.Map;
+
+import org.apache.maven.api.MonotonicClock;
+import org.apache.maven.api.logging.LogLevel;
+import org.apache.maven.api.logging.LogSink;
+import org.apache.maven.api.logging.LoggerManager;
+import org.apache.maven.logging.impl.DefaultLogEvent;
+import org.apache.maven.logging.impl.DefaultLoggerManager;
+import org.slf4j.Marker;
+import org.slf4j.event.Level;
+import org.slf4j.helpers.LegacyAbstractLogger;
+import org.slf4j.spi.LocationAwareLogger;
+
+/**
+ * Thin SLF4J logger that dispatches events to the Maven unified logging API
+ * via {@link LoggerManager}. Level checks are delegated to
+ * {@link DefaultLoggerManager}; formatting is deferred to the {@link LogSink}.
+ *
+ * @since 3.5.0
+ */
+public class MavenSimpleLogger extends LegacyAbstractLogger {
+
+ private static final StackWalker STACK_WALKER = StackWalker.getInstance();
+ final String pluginId;
+ int currentLogLevel = LocationAwareLogger.INFO_INT;
Review Comment:
⚠️ **Missing `volatile`**: `currentLogLevel` is read on every
`isLevelEnabled()` call from any thread and written by level-change methods on
the reconfiguration thread. Without `volatile`, the JVM is free to cache the
value in a register and a level-change will be invisible to other threads. All
peer mutable fields in this PR (`customSink`, `logSink`, `defaultLogLevel`,
`instance`) use `volatile` — this field should too.
```suggestion
volatile int currentLogLevel = LocationAwareLogger.INFO_INT;
```
##########
impl/maven-logging-jul/src/test/java/org/apache/maven/logging/jul/MavenJulHandlerTest.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.logging.jul;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import org.apache.maven.api.logging.LogEvent;
+import org.apache.maven.api.logging.LogLevel;
+import org.apache.maven.api.logging.LogSink;
+import org.apache.maven.logging.impl.DefaultLoggerManager;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+@Timeout(10)
+class MavenJulHandlerTest {
+
+ private DefaultLoggerManager testManager;
+
+ @BeforeEach
+ void installTestManager() {
+ testManager = new DefaultLoggerManager();
+ testManager.setRootLoggerLevel(LogLevel.TRACE);
+ testManager.install();
+ }
+
+ @AfterEach
+ void clearTestManager() {
+ testManager.uninstall();
+ testManager = null;
+ }
+
+ @ParameterizedTest(name = "JUL {0} -> LogLevel.{1}")
+ @CsvSource({
+ "FINEST, TRACE",
+ "FINER, DEBUG",
+ "FINE, DEBUG",
+ "CONFIG, INFO",
+ "INFO, INFO",
+ "WARNING, WARN",
+ "SEVERE, ERROR",
+ })
+ void julLevelMapsToCorrectLogLevel(String julLevelName, String
expectedLogLevel) {
+ Level julLevel = Level.parse(julLevelName);
Review Comment:
🔍 **Missing assertion**: `publishIsReentrantSafe()` only verifies that no
exception is thrown when the `IN_PUBLISH` guard fires. It does not verify that
the normal (non-reentrant) publish path actually formats and delivers the
message correctly — the happy path is entirely untested here. Consider adding a
companion test that installs a capture sink, calls `publish()` without the
guard set, and asserts the event reaches the sink.
##########
compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -1646,8 +1636,9 @@ static void performProfileActivation(final CommandLine
commandLine, final Profil
}
}
- private ExecutionListener determineExecutionListener() {
- ExecutionListener executionListener = new
ExecutionEventLogger(messageBuilderFactory);
+ private ExecutionListener determineExecutionListener(CliRequest
cliRequest) {
+ ExecutionListener executionListener = new ExecutionEventLogger(
+ messageBuilderFactory,
org.slf4j.LoggerFactory.getLogger(ExecutionEventLogger.class), -1);
Review Comment:
⚠️ **`--fail-on-severity` silently broken on the compat path**: passing `-1`
here effectively disables the severity threshold check. The old compat
`ExecutionEventLogger.sessionEnded()` had its
`LogLevelRecorder.hasReachedMaxLevel()` check removed with no replacement in
the compat class — the new check lives only in
`impl/maven-cli/…/ExecutionEventLogger`. As a result, users of the compat
`MavenCli` who set `--fail-on-severity` will see no enforcement: the build will
not fail even when the threshold is exceeded.
##########
impl/maven-jline/src/main/java/org/apache/maven/jline/JLineMessageBuilderFactory.java:
##########
@@ -136,7 +136,18 @@ private MavenStyleResolver() {
@Override
public AttributedStyle resolve(String spec) {
- return styles.computeIfAbsent(spec, this::doResolve);
+ try {
+ return styles.computeIfAbsent(spec, this::doResolve);
+ } catch (IllegalStateException e) {
+ // ConcurrentHashMap.computeIfAbsent throws
IllegalStateException("Recursive update")
+ // when the same map is re-entered from within a
computeIfAbsent call on the same
+ // thread. This can happen during FastTerminal
initialization: JLine's StyleResolver
+ // logs via JUL, MavenJulHandler routes the event into the
Maven logging pipeline,
+ // which may itself call style() → resolve() here before the
first computeIfAbsent
Review Comment:
🔍 **Stale comment**: this comment says `MavenSimpleLogger.renderLevel()` is
what causes the recursive re-entry, but the same PR removes `renderLevel()`
from `MavenSimpleLogger` entirely (the method is gone in
`impl/maven-logging-slf4j/src/main/java/org/apache/maven/logging/slf4j/MavenSimpleLogger.java`).
The comment should be updated to describe the actual post-refactor call chain
so it stays accurate.
##########
impl/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java:
##########
@@ -67,10 +67,16 @@ public class InjectorImpl implements Injector {
private final Set<String> loadedUrls = new HashSet<>();
private final ThreadLocal<Set<Key<?>>> resolutionStack = new
ThreadLocal<>();
+ private final Consumer<String> dumpSink;
private final InjectorDiagnostics diagnostics = new
InjectorDiagnostics(this, bindings, scopes);
private int registrationDepth;
public InjectorImpl() {
+ this(System.out::println);
Review Comment:
⚠️ **System.out default sink**: the no-arg constructor delegates to
`System.out::println`. Any code path that calls `new InjectorImpl()` (including
production code currently using it) will silently write DI diagnostics to
stdout instead of the Maven log sink. Consider defaulting to a no-op sink — or
at minimum a `LoggerFactory.getLogger(InjectorImpl.class)::debug` — so callers
that don't need diagnostics don't accidentally produce output.
##########
impl/maven-logging-slf4j/src/main/java/org/apache/maven/logging/slf4j/MavenSimpleLogger.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.logging.slf4j;
+
+import java.util.Arrays;
+import java.util.Map;
+
+import org.apache.maven.api.MonotonicClock;
+import org.apache.maven.api.logging.LogLevel;
+import org.apache.maven.api.logging.LogSink;
+import org.apache.maven.api.logging.LoggerManager;
+import org.apache.maven.logging.impl.DefaultLogEvent;
+import org.apache.maven.logging.impl.DefaultLoggerManager;
+import org.slf4j.Marker;
+import org.slf4j.event.Level;
+import org.slf4j.helpers.LegacyAbstractLogger;
+import org.slf4j.spi.LocationAwareLogger;
+
+/**
+ * Thin SLF4J logger that dispatches events to the Maven unified logging API
+ * via {@link LoggerManager}. Level checks are delegated to
+ * {@link DefaultLoggerManager}; formatting is deferred to the {@link LogSink}.
+ *
+ * @since 3.5.0
+ */
+public class MavenSimpleLogger extends LegacyAbstractLogger {
+
+ private static final StackWalker STACK_WALKER = StackWalker.getInstance();
+ final String pluginId;
+ int currentLogLevel = LocationAwareLogger.INFO_INT;
Review Comment:
⚠️ **Missing `volatile`**: `currentLogLevel` is read on every
`isLevelEnabled()` call from any thread and written by level-change methods on
the reconfiguration thread. Without `volatile`, the JVM is free to cache the
value in a register and a level-change will be invisible to other threads. All
peer mutable fields in this PR (`customSink`, `logSink`, `defaultLogLevel`,
`instance`) use `volatile` — this field should too.
```suggestion
volatile int currentLogLevel = LocationAwareLogger.INFO_INT;
```
##########
impl/maven-jline/src/main/java/org/apache/maven/jline/JLineMessageBuilderFactory.java:
##########
@@ -136,7 +136,18 @@ private MavenStyleResolver() {
@Override
public AttributedStyle resolve(String spec) {
- return styles.computeIfAbsent(spec, this::doResolve);
+ try {
+ return styles.computeIfAbsent(spec, this::doResolve);
+ } catch (IllegalStateException e) {
+ // ConcurrentHashMap.computeIfAbsent throws
IllegalStateException("Recursive update")
+ // when the same map is re-entered from within a
computeIfAbsent call on the same
+ // thread. This can happen during FastTerminal
initialization: JLine's StyleResolver
+ // logs via JUL, MavenJulHandler routes the event into the
Maven logging pipeline,
+ // which may itself call style() → resolve() here before the
first computeIfAbsent
Review Comment:
🔍 **Stale comment**: this comment says `MavenSimpleLogger.renderLevel()` is
what causes the recursive re-entry, but the same PR removes `renderLevel()`
from `MavenSimpleLogger` entirely (the method is gone in
`impl/maven-logging-slf4j/src/main/java/org/apache/maven/logging/slf4j/MavenSimpleLogger.java`).
The comment should be updated to describe the actual post-refactor call chain
so it stays accurate.
##########
impl/maven-logging-jul/src/test/java/org/apache/maven/logging/jul/MavenJulHandlerTest.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.logging.jul;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import org.apache.maven.api.logging.LogEvent;
+import org.apache.maven.api.logging.LogLevel;
+import org.apache.maven.api.logging.LogSink;
+import org.apache.maven.logging.impl.DefaultLoggerManager;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+@Timeout(10)
+class MavenJulHandlerTest {
+
+ private DefaultLoggerManager testManager;
+
+ @BeforeEach
+ void installTestManager() {
+ testManager = new DefaultLoggerManager();
+ testManager.setRootLoggerLevel(LogLevel.TRACE);
+ testManager.install();
+ }
+
+ @AfterEach
+ void clearTestManager() {
+ testManager.uninstall();
+ testManager = null;
+ }
+
+ @ParameterizedTest(name = "JUL {0} -> LogLevel.{1}")
+ @CsvSource({
+ "FINEST, TRACE",
+ "FINER, DEBUG",
+ "FINE, DEBUG",
+ "CONFIG, INFO",
+ "INFO, INFO",
+ "WARNING, WARN",
+ "SEVERE, ERROR",
+ })
+ void julLevelMapsToCorrectLogLevel(String julLevelName, String
expectedLogLevel) {
+ Level julLevel = Level.parse(julLevelName);
Review Comment:
🔍 **Missing assertion**: `publishIsReentrantSafe()` only verifies that no
exception is thrown when the `IN_PUBLISH` guard fires. It does not verify that
the normal (non-reentrant) publish path actually formats and delivers the
message correctly — the happy path is entirely untested here. Consider adding a
companion test that installs a capture sink, calls `publish()` without the
guard set, and asserts the event reaches the sink.
##########
compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -1646,8 +1636,9 @@ static void performProfileActivation(final CommandLine
commandLine, final Profil
}
}
- private ExecutionListener determineExecutionListener() {
- ExecutionListener executionListener = new
ExecutionEventLogger(messageBuilderFactory);
+ private ExecutionListener determineExecutionListener(CliRequest
cliRequest) {
+ ExecutionListener executionListener = new ExecutionEventLogger(
+ messageBuilderFactory,
org.slf4j.LoggerFactory.getLogger(ExecutionEventLogger.class), -1);
Review Comment:
⚠️ **`--fail-on-severity` silently broken on the compat path**: passing `-1`
here effectively disables the severity threshold check. The old compat
`ExecutionEventLogger.sessionEnded()` had its
`LogLevelRecorder.hasReachedMaxLevel()` check removed with no replacement in
the compat class — the new check lives only in
`impl/maven-cli/…/ExecutionEventLogger`. As a result, users of the compat
`MavenCli` who set `--fail-on-severity` will see no enforcement: the build will
not fail even when the threshold is exceeded.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]