diff --git a/api/all/src/main/java/io/opentelemetry/api/common/ArrayBackedAttributes.java b/api/all/src/main/java/io/opentelemetry/api/common/ArrayBackedAttributes.java index 165c9ffe2e2..539fc2f6393 100644 --- a/api/all/src/main/java/io/opentelemetry/api/common/ArrayBackedAttributes.java +++ b/api/all/src/main/java/io/opentelemetry/api/common/ArrayBackedAttributes.java @@ -41,7 +41,7 @@ public AttributesBuilder toBuilder() { return new ArrayBackedAttributesBuilder(new ArrayList<>(data())); } - @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") // safe cast: values are stored internally keyed by AttributeKey @Override @Nullable public T get(AttributeKey key) { diff --git a/api/all/src/main/java/io/opentelemetry/api/common/ArrayBackedAttributesBuilder.java b/api/all/src/main/java/io/opentelemetry/api/common/ArrayBackedAttributesBuilder.java index af575a61e36..1872808898a 100644 --- a/api/all/src/main/java/io/opentelemetry/api/common/ArrayBackedAttributesBuilder.java +++ b/api/all/src/main/java/io/opentelemetry/api/common/ArrayBackedAttributesBuilder.java @@ -49,12 +49,11 @@ public AttributesBuilder put(AttributeKey key, @Nullable T value) { @Override @SuppressWarnings({"unchecked", "rawtypes"}) + // Safe: Attributes guarantees iteration over matching AttributeKey / value pairs. public AttributesBuilder putAll(Attributes attributes) { if (attributes == null) { return this; } - // Attributes must iterate over their entries with matching types for key / value, so this - // downcast to the raw type is safe. attributes.forEach((key, value) -> put((AttributeKey) key, value)); return this; }