sdj3261 opened a new pull request, #7599:
URL: https://github.com/apache/gravitino/pull/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");
}
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]