From 5565337ec07281f8b58f65e275185112811357c0 Mon Sep 17 00:00:00 2001 From: kkondaka <41027584+kkondaka@users.noreply.github.com> Date: Fri, 23 Jun 2023 10:07:09 -0700 Subject: [PATCH] Fix addTags API in EventMetadata (#2926) Signed-off-by: Krishna Kondaka Co-authored-by: Krishna Kondaka --- .../model/event/DefaultEventMetadata.java | 4 +++- .../model/event/DefaultEventMetadataTest.java | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/event/DefaultEventMetadata.java b/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/event/DefaultEventMetadata.java index 24384c2ad3..e2ce55caa2 100644 --- a/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/event/DefaultEventMetadata.java +++ b/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/event/DefaultEventMetadata.java @@ -97,7 +97,9 @@ public Boolean hasTags(final List tagsList) { @Override public void addTags(final List newTags) { - tags.addAll(newTags); + if (Objects.nonNull(newTags)) { + tags.addAll(newTags); + } } @Override diff --git a/data-prepper-api/src/test/java/org/opensearch/dataprepper/model/event/DefaultEventMetadataTest.java b/data-prepper-api/src/test/java/org/opensearch/dataprepper/model/event/DefaultEventMetadataTest.java index 18f15f60d9..fa624a9e2b 100644 --- a/data-prepper-api/src/test/java/org/opensearch/dataprepper/model/event/DefaultEventMetadataTest.java +++ b/data-prepper-api/src/test/java/org/opensearch/dataprepper/model/event/DefaultEventMetadataTest.java @@ -199,6 +199,18 @@ void fromEventMetadata_returns_matching_EventMetadata() { assertThat(copiedMetadata.getAttributes(), not(sameInstance(attributes))); } + @Test + public void testEventMetadata_withNullTags() { + final String testEventType = UUID.randomUUID().toString(); + + final EventMetadata eventMetadata = DefaultEventMetadata.builder() + .withEventType(testEventType) + .build(); + assertThat(eventMetadata, notNullValue()); + eventMetadata.addTags(null); + assertThat(eventMetadata.getTags(), equalTo(Collections.emptySet())); + } + @Test public void testBuild_withTags() { final String testEventType = UUID.randomUUID().toString();