Skip to content
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

Inconsistent null checks in ImmutableSortedMap #2962

Closed
johnsoneal opened this issue Oct 9, 2017 · 2 comments
Closed

Inconsistent null checks in ImmutableSortedMap #2962

johnsoneal opened this issue Oct 9, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@johnsoneal
Copy link

When creating ImmutableSortedMap instances the documentation for methods copyOf and copyOfSorted state:

"NullPointerException - if any key or value in map is null"

However this behavior is not consistent an it is possible to create a map with null values.

Given a HashMap of stings with map:{a:null} all the copOf methods throw as expected, with a map:{a:null, b:two} then none of the copyOf methods throw.

Given a SortedMap of strings with map:{a:null} and a natural order copyOf and copyOfSorted all throw as expected; with a map:{a:null, b:two} then copyOf(Map) and copyOfSorted(SortedMap) throw; copyOf(Iterable), copyOf(Iterable, Comparator), copyOf(Map, Comparator) do not throw; with a map:{a:one, b:null}
copyOf and copyOfSorted all throw as expected.

From what I can tell this behavior is only present for maps with two elements and only when the null is the first value of the first key. The of and builder methods are not effected an throw as expected.

@cpovirk
Copy link
Member

cpovirk commented Oct 9, 2017

Nice catch. Likely the problem is in the else case of fromEntries.

@cpovirk cpovirk added this to the NEXT milestone Oct 10, 2017
@cpovirk
Copy link
Member

cpovirk commented Oct 10, 2017

9bcedd8

@cpovirk cpovirk closed this as completed Oct 10, 2017
@cgdecker cgdecker modified the milestones: NEXT, 23.2 Oct 11, 2017
@cpovirk cpovirk changed the title Inconsistant null checks in ImmutableSortedMap Inconsistent null checks in ImmutableSortedMap May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants