diff --git a/dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/util/WellKnownClasses.java b/dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/util/WellKnownClasses.java index de4742a7512..72aa94612a8 100644 --- a/dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/util/WellKnownClasses.java +++ b/dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/util/WellKnownClasses.java @@ -14,6 +14,7 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalDouble; @@ -187,6 +188,22 @@ public class WellKnownClasses { THROWABLE_SPECIAL_FIELDS.put("cause", ThrowableFields::cause); } + private static final List SAFE_COLLECTION_PACKAGES = + Arrays.asList( + "java.", // JDK base module + "com.google.protobuf.", // Google ProtoBuf + "com.google.common.collect.", // Google Guava + "it.unimi.dsi.fastutil." // fastutil + ); + + private static final List SAFE_MAP_PACKAGES = + Arrays.asList( + "java.", // JDK base module + "com.google.protobuf.", // Google ProtoBuf + "com.google.common.collect.", // Google Guava + "it.unimi.dsi.fastutil." // fastutil + ); + /** * @return true if type is a final class and toString implementation is well known and side effect * free @@ -207,13 +224,10 @@ public static boolean isToStringSafe(String concreteType) { /** @return true if collection implementation is safe to call (only in-memory) */ public static boolean isSafe(Collection collection) { String className = collection.getClass().getTypeName(); - if (className.startsWith("java.")) { - // All Collection implementations from JDK base module are considered as safe - return true; - } - if (className.startsWith("com.google.protobuf.")) { - // All Collection implementations from Google ProtoBuf are considered as safe - return true; + for (String safePackage : SAFE_COLLECTION_PACKAGES) { + if (className.startsWith(safePackage)) { + return true; + } } return false; } @@ -221,13 +235,10 @@ public static boolean isSafe(Collection collection) { /** @return true if map implementation is safe to call (only in-memory) */ public static boolean isSafe(Map map) { String className = map.getClass().getTypeName(); - if (className.startsWith("java.")) { - // All Map implementations from JDK base module are considered as safe - return true; - } - if (className.startsWith("com.google.protobuf.")) { - // All Map implementations from Google ProtoBuf are considered as safe - return true; + for (String safePackage : SAFE_MAP_PACKAGES) { + if (className.startsWith(safePackage)) { + return true; + } } return false; }