Skip to content

Commit 1c443c5

Browse files
fix: maven-failsafe-plugin 3.5.5 workaround
1 parent 21795b3 commit 1c443c5

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

dd-java-agent/instrumentation/maven/maven-3.2.1/src/test/groovy/MavenInstrumentationTest.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import datadog.trace.api.config.CiVisibilityConfig
22
import datadog.trace.civisibility.CiVisibilityInstrumentationTest
33
import org.apache.maven.cli.MavenCli
44
import org.codehaus.plexus.util.FileUtils
5+
import org.slf4j.MDC
56
import spock.lang.TempDir
67

78
import java.nio.file.Path
@@ -18,6 +19,14 @@ class MavenInstrumentationTest extends CiVisibilityInstrumentationTest {
1819

1920
@Override
2021
def setup() {
22+
// Workaround for maven-surefire 3.5.5 bug (https://github.com/apache/maven-surefire/pull/3241):
23+
// ThreadedStreamConsumer$Pumper.run() calls MDC.setContextMap(MDC.getCopyOfContextMap()),
24+
// but LogbackMDCAdapter.getCopyOfContextMap() returns null when MDC is uninitialized,
25+
// and LogbackMDCAdapter.setContextMap(null) throws NPE via HashMap.putAll(null).
26+
// Pre-initializing MDC ensures getCopyOfContextMap() returns an empty map instead of null.
27+
MDC.put("_init", "true")
28+
MDC.remove("_init")
29+
2130
System.setProperty("maven.multiModuleProjectDirectory", projectFolder.toAbsolutePath().toString())
2231
givenMavenProjectFiles((String) specificationContext.currentIteration.dataVariables.testcaseName)
2332
givenMavenDependenciesAreLoaded()

0 commit comments

Comments
 (0)