Skip to content

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

Merged
cpovirk merged 1 commit intomainfrom
objectshash
Jul 22, 2025
Merged

Allow calls to Objects.hash with a null varargs array.#127
cpovirk merged 1 commit intomainfrom
objectshash

Conversation

@cpovirk
Copy link
Copy Markdown
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
Copy link
Copy Markdown
Collaborator

@wmdietl wmdietl left a comment

Choose a reason for hiding this comment

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

Sure, for consistency this makes sense.
Sorry for the delay.

@wmdietl wmdietl assigned cpovirk and unassigned wmdietl Jul 22, 2025
@cpovirk cpovirk merged commit 6cceb18 into main Jul 22, 2025
20 checks passed
@cpovirk cpovirk deleted the objectshash branch July 22, 2025 22:40
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