Merge pull request #1247 from DataDog/tyler/bb-raw

Set ByteBuddy raw setting at startup
This commit is contained in:
Tyler Benson 2020-02-21 16:30:24 -08:00 committed by GitHub
commit b27b30d913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import java.util.ServiceLoader;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.agent.builder.ResettableClassFileTransformer;
import net.bytebuddy.description.type.TypeDefinition;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.matcher.ElementMatcher;
@ -50,6 +51,8 @@ public class AgentInstaller {
final Instrumentation inst, final AgentBuilder.Listener... listeners) {
INSTRUMENTATION = inst;
addByteBuddyRawSetting();
AgentBuilder agentBuilder =
new AgentBuilder.Default()
.disableClassFormatChanges()
@ -93,6 +96,23 @@ public class AgentInstaller {
return agentBuilder.installOn(inst);
}
private static void addByteBuddyRawSetting() {
final String savedPropertyValue = System.getProperty(TypeDefinition.RAW_TYPES_PROPERTY);
try {
System.setProperty(TypeDefinition.RAW_TYPES_PROPERTY, "true");
final boolean rawTypes = TypeDescription.AbstractBase.RAW_TYPES;
if (!rawTypes) {
log.debug("Too late to enable {}", TypeDefinition.RAW_TYPES_PROPERTY);
}
} finally {
if (savedPropertyValue == null) {
System.clearProperty(TypeDefinition.RAW_TYPES_PROPERTY);
} else {
System.setProperty(TypeDefinition.RAW_TYPES_PROPERTY, savedPropertyValue);
}
}
}
private static ElementMatcher.Junction<Object> matchesConfiguredExcludes() {
final List<String> excludedClasses = Config.get().getExcludedClasses();
ElementMatcher.Junction matcher = none();