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

Inconsistant null checks in ImmutableSortedMap #2962

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

Comments

Projects
None yet
4 participants
@johnsoneal

johnsoneal commented Oct 9, 2017

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

This comment has been minimized.

Show comment
Hide comment
@cpovirk

cpovirk Oct 9, 2017

Member

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

Member

cpovirk commented Oct 9, 2017

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

@cpovirk

This comment has been minimized.

Show comment
Hide comment
@cpovirk
Member

cpovirk commented Oct 10, 2017

@cpovirk cpovirk closed this Oct 10, 2017

@cgdecker cgdecker modified the milestones: NEXT, 23.2 Oct 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment