Skip to content

Add readImmutableMap for Java Map #86353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 4, 2022

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented May 2, 2022

The readImmutableMap method of StreamInput reads an ImmutableOpenMap. As
we work towards #86239, we want to continue using immutable maps, but
instead use those from the JDK. This commit renames the existing
readImmutableMap to readImmutableOpenMap, and reimplements the existing
method to return an immutable Map using Map.of and Map.ofEntries.

relates #86239

The readImmutableMap method of StreamInput reads an ImmutableOpenMap. As
we work towards elastic#86239, we want to continue using immutable maps, but
instead use those from the JDK. This commit renames the existing
readImmutableMap to readImmutableOpenMap, and reimplements the existing
method to return an immutable Map using Map.of and Map.ofEntries.

relates elastic#86239
@rjernst rjernst added :Core/Infra/Core Core issues without another label >refactoring v8.3.0 labels May 2, 2022
@rjernst rjernst requested a review from original-brownbear May 2, 2022 16:25
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label May 2, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@@ -680,13 +680,28 @@ public Map<String, Object> readMap() throws IOException {
return (Map<String, Object>) readGenericValue();
}

public <K, V> Map<K, V> readImmutableMap(Writeable.Reader<K> keyReader, Writeable.Reader<V> valueReader) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a comment here, making it clear that valueReader must never return null? I see we're using the immutable open map with optional strings for the values, that will throw NPEs with Map.of( and can't be ported directly. Might be nice to make that clear in the docs?

@rjernst rjernst merged commit 2daf287 into elastic:master May 4, 2022
@rjernst rjernst deleted the hppc/immutable_reader branch May 4, 2022 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >refactoring Team:Core/Infra Meta label for core/infra team v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants