This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 38220a1bc8 [#7590] fix(dto): use instanceof TopicDTO instead of Topic
for equals() (#7599)
38220a1bc8 is described below
commit 38220a1bc871f813ceb9cd859ef7ae817b50cee1
Author: 신동재 <[email protected]>
AuthorDate: Tue Jul 8 08:15:10 2025 +0900
[#7590] fix(dto): use instanceof TopicDTO instead of Topic for equals()
(#7599)
[#7590] fix(dto): use instanceof TopicDTO instead of Topic for equals()
### What changes were proposed in this pull request?
- Modify `TopicDTO.equals` method:
- Replace `instanceof Topic` check with `instanceof TopicDTO`
- Ensure correct type checking in the equals method
### Why are the changes needed?
- The current `equals` implementation in `TopicDTO` incorrectly checks
`instanceof Topic`.
- This could result in comparing objects of different implementations of
`Topic`, potentially causing a `ClassCastException` and breaking the
equals symmetry contract.
- This change ensures that the equals method uses `instanceof TopicDTO`
instead, performing the type check correctly and safely.
Fix: #7590
### Does this PR introduce _any_ user-facing change?
No user-facing changes.
### How was this patch tested?
The test code was written and used for manual verification but was not
committed to the repository.
public class TestTopicDTO {
@Test
void testShouldBeEqual_whenAllFieldsAreSame() {
Map<String, String> props = Collections.singletonMap("key1", "value1");
TopicDTO t1 =
TopicDTO.builder().withName("topicA").withComment("comment").withProperties(props).build();
TopicDTO t2 =
TopicDTO.builder().withName("topicA").withComment("comment").withProperties(props).build();
Assertions.assertEquals(t1, t2, "TopicDTOs with same fields should be
equal");
}
@Test
void testShouldNotBeEqual_whenNamesAreDifferent() {
Map<String, String> props = Collections.singletonMap("key1", "value1");
TopicDTO t1 =
TopicDTO.builder().withName("topicA").withComment("comment").withProperties(props).build();
TopicDTO t2 =
TopicDTO.builder().withName("topicB").withComment("comment").withProperties(props).build();
Assertions.assertNotEquals(t1, t2, "TopicDTOs with different names
should not be equal");
}
}
---
common/src/main/java/org/apache/gravitino/dto/messaging/TopicDTO.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git
a/common/src/main/java/org/apache/gravitino/dto/messaging/TopicDTO.java
b/common/src/main/java/org/apache/gravitino/dto/messaging/TopicDTO.java
index afbc264f9b..44ca689a3f 100644
--- a/common/src/main/java/org/apache/gravitino/dto/messaging/TopicDTO.java
+++ b/common/src/main/java/org/apache/gravitino/dto/messaging/TopicDTO.java
@@ -89,7 +89,7 @@ public class TopicDTO implements Topic {
if (this == o) {
return true;
}
- if (!(o instanceof Topic)) {
+ if (!(o instanceof TopicDTO)) {
return false;
}
TopicDTO topicDTO = (TopicDTO) o;