From 77cb569538969ca50c7edc2e4c1e8db1452d5a24 Mon Sep 17 00:00:00 2001 From: Stuart McCulloch Date: Thu, 24 Apr 2025 18:17:04 +0100 Subject: [PATCH] Ensure net.bytebuddy.raw is set to true when ConfigTransformSpockExtension is installed This matches the same setting used by AgentInstaller which avoids spurious test failures in agent-tooling, specifically TypeFactoryForkedTest. This requires raw-types enabled to match the behaviour when installing the tracer with -javaagent. Without this byte-buddy will use dufferent code paths involving generic checks, which can lead to test failures using recent versions of byte-buddy (specifically going between full and outline types, where outlines are always raw-types by their nature.) These failures would not happen when using -javaagent because AgentInstaller forces the use of the raw-types setting. ConfigTransformSpockExtension should therefore do the same. Note we can't set this property in TypeFactoryForkedTest because by then it is too late, byte-buddy is already confgured by ConfigTransformSpockExtension and the raw-types value cannot be changed. --- .../tooling/bytebuddy/outline/TypeFactoryForkedTest.groovy | 4 ++++ .../trace/test/util/ConfigTransformSpockExtension.groovy | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/tooling/bytebuddy/outline/TypeFactoryForkedTest.groovy b/dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/tooling/bytebuddy/outline/TypeFactoryForkedTest.groovy index cdd69dbb464..6ec2769fe6d 100644 --- a/dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/tooling/bytebuddy/outline/TypeFactoryForkedTest.groovy +++ b/dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/tooling/bytebuddy/outline/TypeFactoryForkedTest.groovy @@ -2,6 +2,7 @@ package datadog.trace.agent.tooling.bytebuddy.outline import datadog.trace.agent.tooling.bytebuddy.ClassFileLocators import datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers +import net.bytebuddy.description.type.TypeDescription import spock.lang.Shared import spock.lang.Specification @@ -28,6 +29,9 @@ class TypeFactoryForkedTest extends Specification { def hasContextField = declaresContextField('java.lang.Runnable', 'java.lang.String') def "can mix full types with outlines"() { + expect: + TypeDescription.AbstractBase.RAW_TYPES // this test relies on raw-types + when: def systemLoader = ClassLoader.systemClassLoader def systemLocator = ClassFileLocators.classFileLocator(systemLoader) diff --git a/utils/test-utils/src/main/groovy/datadog/trace/test/util/ConfigTransformSpockExtension.groovy b/utils/test-utils/src/main/groovy/datadog/trace/test/util/ConfigTransformSpockExtension.groovy index 625c43d9af3..57373547f11 100644 --- a/utils/test-utils/src/main/groovy/datadog/trace/test/util/ConfigTransformSpockExtension.groovy +++ b/utils/test-utils/src/main/groovy/datadog/trace/test/util/ConfigTransformSpockExtension.groovy @@ -18,6 +18,11 @@ import static net.bytebuddy.matcher.ElementMatchers.none * Transforms the Config class to make its INSTANCE field non-final and volatile. */ class ConfigTransformSpockExtension implements IGlobalExtension { + static { + // same setting as AgentInstaller to avoid spurious agent-tooling test failures + System.setProperty("net.bytebuddy.raw", "true") + } + static final String INST_CONFIG = "datadog.trace.api.InstrumenterConfig" static final String CONFIG = "datadog.trace.api.Config"