diff --git a/dd-java-agent/instrumentation/gradle/src/main/groovy/datadog/trace/instrumentation/gradle/CiVisibilityPluginExtension.java b/dd-java-agent/instrumentation/gradle/src/main/groovy/datadog/trace/instrumentation/gradle/CiVisibilityPluginExtension.java index c681eb2c0da..a8fc82a5fdf 100644 --- a/dd-java-agent/instrumentation/gradle/src/main/groovy/datadog/trace/instrumentation/gradle/CiVisibilityPluginExtension.java +++ b/dd-java-agent/instrumentation/gradle/src/main/groovy/datadog/trace/instrumentation/gradle/CiVisibilityPluginExtension.java @@ -146,9 +146,15 @@ private static Map getProjectProperties(Test task) { private void applyJacocoSettings(Path jvmExecutable, JacocoTaskExtension jacocoTaskExtension) { CiVisibilityService ciVisibilityService = getCiVisibilityService().get(); - List taskExcludeClassLoader = jacocoTaskExtension.getExcludeClassLoaders(); - if (taskExcludeClassLoader != null) { - taskExcludeClassLoader.addAll(ciVisibilityService.getExcludeClassLoaders()); + List taskExcludeClassLoaders = jacocoTaskExtension.getExcludeClassLoaders(); + if (taskExcludeClassLoaders != null) { + // taskExcludeClassLoaders list may be immutable, so we need to construct a new one + List ciVisExcludedClassLoaders = ciVisibilityService.getExcludeClassLoaders(); + List updatedTaskExcludeClassLoaders = + new ArrayList<>(taskExcludeClassLoaders.size() + ciVisExcludedClassLoaders.size()); + updatedTaskExcludeClassLoaders.addAll(taskExcludeClassLoaders); + updatedTaskExcludeClassLoaders.addAll(ciVisExcludedClassLoaders); + jacocoTaskExtension.setExcludeClassLoaders(updatedTaskExcludeClassLoaders); } else { jacocoTaskExtension.setExcludeClassLoaders( new ArrayList<>(ciVisibilityService.getExcludeClassLoaders()));