Skip to content

Commit 74abb34

Browse files
authored
fix: potential NullPointerException in Value#hashCode (#4046)
The Value#hashCode() method throwed a NullPointerException for untyped values.
1 parent d05dab6 commit 74abb34

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,10 @@ public final int hashCode() {
17161716
* while calculating valueHash of Float32 type. Note that this is not applicable for composite
17171717
* types containing FLOAT32.
17181718
*/
1719-
if (type.getCode() == Type.Code.FLOAT32 && !isNull && Float.isNaN(getFloat32())) {
1719+
if (type != null
1720+
&& type.getCode() == Type.Code.FLOAT32
1721+
&& !isNull
1722+
&& Float.isNaN(getFloat32())) {
17201723
typeToHash = Type.float64();
17211724
}
17221725

google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public void untyped() {
9494
assertNull(v.getType());
9595
assertFalse(v.isNull());
9696
assertSame(proto, v.toProto());
97+
assertNotEquals(0, v.hashCode());
98+
assertEquals(v, Value.untyped(proto));
9799

98100
assertEquals(
99101
v, Value.untyped(com.google.protobuf.Value.newBuilder().setStringValue("test").build()));

0 commit comments

Comments
 (0)