Don't call `map.get()` in the `put(..)` case
MODIFY
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/WeakMap.java
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/WeakMap.java
@@ -109,15 +109,20 @@ public interface WeakMap<K, V> {
@Override
public V computeIfAbsent(final K key, final ValueSupplier<? super K, ? extends V> supplier) {
// We can't use computeIfAbsent since it was added in 1.8.
- if (!map.containsKey(key)) {
- synchronized (this) {
- if (!map.containsKey(key)) {
- map.put(key, supplier.get(key));
- }
- }
+ if (map.containsKey(key)) {
+ return map.get(key);
}
+ synchronized (this) {
+ if (map.containsKey(key)) {
return map.get(key);
+ } else {
+ final V value = supplier.get(key);
+
+ map.put(key, value);
+ return value;
+ }
+ }
}
@Override

MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/WeakMapSuppliers.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/WeakMapSuppliers.java
@@ -87,15 +87,20 @@ class WeakMapSuppliers {
@Override
public V computeIfAbsent(final K key, final ValueSupplier<? super K, ? extends V> supplier) {
- if (!map.containsKey(key)) {
- synchronized (this) {
- if (!map.containsKey(key)) {
- map.put(key, supplier.get(key));
- }
- }
+ if (map.containsKey(key)) {
+ return map.get(key);
}
+ synchronized (this) {
+ if (map.containsKey(key)) {
return map.get(key);
+ } else {
+ final V value = supplier.get(key);
+
+ map.put(key, value);
+ return value;
+ }
+ }
}
}

Don't call `map.get()` in the `put(..)` case