Fix TopicPartitionOffset Hash Code (NPE)

**cherry-pick to all supported**
This commit is contained in:
Gary Russell
2022-04-14 16:10:11 -04:00
committed by Artem Bilan
parent cbca786f15
commit 2f45a8200d
2 changed files with 11 additions and 2 deletions

View File

@@ -213,7 +213,7 @@ public class TopicPartitionOffset {
@Override
public int hashCode() {
return this.topicPartition.hashCode() + this.position.hashCode();
return Objects.hash(this.topicPartition, this.position);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020 the original author or authors.
* Copyright 2020-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,9 @@ package org.springframework.kafka.support;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Objects;
import org.apache.kafka.common.TopicPartition;
import org.junit.jupiter.api.Test;
import org.springframework.kafka.support.TopicPartitionOffset.SeekPosition;
@@ -35,4 +38,10 @@ public class TopicPartitionOffsetTests {
.isNotEqualTo(new TopicPartitionOffset("foo", 1, SeekPosition.END).hashCode());
}
@Test
void hashCodeNPE() {
assertThat(new TopicPartitionOffset("foo", 0).hashCode())
.isEqualTo(Objects.hash(new TopicPartition("foo", 0), null));
}
}