Avoid loading `Config` in `DDSpecification`
Loading `Config` in static section of `DDSpecification` happens before
bootstrap jar has been setup. This in turn causes problems down the
road because some of the classes are later loaded from bootstrap and
confuse things.
@@ -6,8 +6,6 @@ import net.bytebuddy.dynamic.ClassFileLocator
import net.bytebuddy.dynamic.Transformer
import spock.lang.Specification
-import java.lang.reflect.Modifier
-
import static net.bytebuddy.description.modifier.FieldManifestation.VOLATILE
import static net.bytebuddy.description.modifier.Ownership.STATIC
import static net.bytebuddy.description.modifier.Visibility.PUBLIC
@@ -17,12 +15,6 @@ import static net.bytebuddy.matcher.ElementMatchers.none
abstract class DDSpecification extends Specification {
private static final String CONFIG = "datadog.trace.api.Config"
- static class ConfigInstance {
- // Wrapped in a static class to lazy load.
- static final CONFIG_INSTANCE_FIELD = Class.forName(CONFIG).getDeclaredField("INSTANCE")
- static final RUNTIME_ID_FIELD = Class.forName(CONFIG).getDeclaredField("runtimeId")
- }
-
static {
makeConfigInstanceModifiable()
}
@@ -36,7 +28,6 @@ abstract class DDSpecification extends Specification {
}
def instrumentation = ByteBuddyAgent.install()
- final transformer =
new AgentBuilder.Default()
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(AgentBuilder.RedefinitionStrategy.Listener.ErrorEscalating.FAIL_FAST)
@@ -59,20 +50,5 @@ abstract class DDSpecification extends Specification {
}
.installOn(instrumentation)
isConfigInstanceModifiable = true
-
- final field = ConfigInstance.CONFIG_INSTANCE_FIELD
- assert Modifier.isPublic(field.getModifiers())
- assert Modifier.isStatic(field.getModifiers())
- assert Modifier.isVolatile(field.getModifiers())
- assert !Modifier.isFinal(field.getModifiers())
-
- final runtimeIdField = ConfigInstance.RUNTIME_ID_FIELD
- assert Modifier.isPublic(runtimeIdField.getModifiers())
- assert !Modifier.isStatic(ConfigInstance.RUNTIME_ID_FIELD.getModifiers())
- assert Modifier.isVolatile(runtimeIdField.getModifiers())
- assert !Modifier.isFinal(runtimeIdField.getModifiers())
-
- // No longer needed (Unless class gets retransformed somehow).
- instrumentation.removeTransformer(transformer)
}
}
