From a8ea7cb3170fb9932e3c5d750f2a73d41b455279 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Tue, 1 Mar 2022 01:46:25 +0200 Subject: [PATCH] Fix android desugaring for HashMap.forEach (#5468) --- .../api/instrumenter/UnsafeAttributes.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UnsafeAttributes.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UnsafeAttributes.java index 9284d1a062a3..5d08e9fb20b3 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UnsafeAttributes.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UnsafeAttributes.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import java.util.HashMap; import java.util.Map; +import java.util.function.BiConsumer; /** * The {@link AttributesBuilder} and {@link Attributes} used by the instrumentation API. We are able @@ -68,4 +69,12 @@ public AttributesBuilder putAll(Attributes attributes) { attributes.forEach(this::put); return this; } + + @Override + public void forEach(BiConsumer, ? super Object> action) { + // https://github.com/open-telemetry/opentelemetry-java/issues/4161 + // Help out android desugaring by having an explicit call to HashMap.forEach, when forEach is + // just called through Attributes.forEach desugaring is unable to correctly handle it. + super.forEach(action); + } }