Update javadoc to allow null/empty attr values (#5616)

This commit is contained in:
jason plumb 2023-07-11 10:41:43 -07:00 committed by GitHub
parent a781ba8fa9
commit 16e7113dcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -91,8 +91,7 @@ public interface Span extends ImplicitContextKeyed {
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
* the key, the old value is replaced by the specified value.
*
* <p>If a null or empty String {@code value} is passed in, the behavior is undefined, and hence
* strongly discouraged.
* <p>Empty String "" and null are valid attribute {@code value}, but not valid keys.
*
* <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and
* pre-allocate your keys, if possible.

View File

@ -578,4 +578,11 @@ class AttributesTest {
assertThatCode(() -> myAttributesBuilder.remove(stringKey("foo"))).doesNotThrowAnyException();
assertThatCode(() -> myAttributesBuilder.removeIf(unused -> false)).doesNotThrowAnyException();
}
@Test
void emptyValueIsValid() {
AttributeKey<String> key = stringKey("anything");
Attributes attributes = Attributes.of(key, "");
assertThat(attributes.get(key)).isEqualTo("");
}
}