Skip to content

Commit d0faf19

Browse files
committed
Allow calls to Objects.hash with a null varargs array.
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.
1 parent e717210 commit d0faf19

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/java.base/share/classes/java/util/Objects.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static int hashCode(@Nullable Object o) {
139139
* @see Arrays#hashCode(Object[])
140140
* @see List#hashCode
141141
*/
142-
public static int hash(@Nullable Object... values) {
142+
public static int hash(@Nullable Object @Nullable ... values) {
143143
return Arrays.hashCode(values);
144144
}
145145

0 commit comments

Comments
 (0)