Skip to content

Increase test coverage and bug fix in JacksonEvent#6181

Merged
dlvenable merged 2 commits into
opensearch-project:mainfrom
dlvenable:jackson-event-test-coverage
Nov 4, 2025
Merged

Increase test coverage and bug fix in JacksonEvent#6181
dlvenable merged 2 commits into
opensearch-project:mainfrom
dlvenable:jackson-event-test-coverage

Conversation

@dlvenable

Copy link
Copy Markdown
Member

Description

I noticed that there was some low test coverage in JacksonEvent for putting maps along with support to rename invalid key characters. When I added the test coverage, I also found that this code path would fail in the input Map is immutable because the code attempts to modify the map.

This PR adds additional test coverage. It also fixes that bug by copying the map.

Issues Resolved

N/A

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…odify input maps which may be immutable.

Signed-off-by: David Venable <dlv@amazon.com>

@KarstenSchnitter KarstenSchnitter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor suggestion. Otherwise looks good to me.

Comment on lines +164 to +167
if (!newKey.equals(key)) {
toAdd.put(newKey, value);
iterator.remove();
replacementMap.put(newKey, value);
} else {
replacementMap.put(key, value);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you just use the newKey in both cases now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I just pushed a new revision with this.

Signed-off-by: David Venable <dlv@amazon.com>

@KarstenSchnitter KarstenSchnitter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

final Map<String, String> mapToPut = Map.of(key, value);

final EventKey eventKey = new JacksonEventKey("myMap");
event.put(eventKey, mapToPut, false);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No assertion needed here?


void normalizeKeys(Map<String, Object> map) {
Map<String, Object> toAdd = new HashMap<>();
private Map<String, Object> normalizeKeys(final Map<String, Object> map) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that there could be existing use cases that are functioning based on the expectation that the map they are passing gets modified?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@san81 , Possibly, but I don't think we should support that. For example, if you create the Map in the builder that always copies.

@dlvenable dlvenable merged commit 2c3b8e0 into opensearch-project:main Nov 4, 2025
46 of 47 checks passed
@dlvenable dlvenable deleted the jackson-event-test-coverage branch November 4, 2025 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants