Skip to content

Allow calls to Objects.hash with a null varargs array. #127

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cpovirk
Copy link
Collaborator

@cpovirk cpovirk commented Jul 1, 2025

The documentation if anything implies that a null array is not
allowed. But it is, since the method delegates straight to
Arrays.hashCode, which accepts null (and even documents as much).
The JDK would be within its rights to change that in the future, but I
can't imagine they would risk the compatibility problems it would cause.

I do grant that it's somewhat unlikely that callers would pass a null
array. The reason that I care is that I'm looking at making Guava's
ancient
Objects.hashCode
call Java's Objects.hash—leading to a nullness error with the current
JDK stubs.

The documentation if anything implies that a null array is _not_
allowed. But it is, since the method delegates straight to
`Arrays.hashCode`, which accepts `null` (and even documents as much).
The JDK would be within its rights to change that in the future, but I
can't imagine they would risk the compatibility problems it would cause.

I do grant that it's somewhat unlikely that callers would pass a null
array. The reason that I care is that I'm looking at making Guava's
ancient
[`Objects.hashCode`](https://github.com/google/guava/blob/990557ca1295e068e7a83a0ee4556ccbca2bc240/guava/src/com/google/common/base/Objects.java#L76)
call Java's `Objects.hash`-leading to a nullness error with the current
JDK stubs.
@cpovirk cpovirk requested a review from wmdietl July 1, 2025 20:26
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.

2 participants