gmethvin opened a new issue #9438:
URL: https://github.com/apache/pulsar/issues/9438


   **Describe the bug**
   
   In some places in the API it is possible to get different subtypes of 
`MessageId`s in different contexts. For example, when implementing a 
`ConsumerInterceptor`, the Pulsar client may provide a `MessageIdImpl` in 
`beforeConsume` but provide a `BatchMessageIdImpl` in `onAcknowledge` (with a 
batch ID of `-1`). It's often useful to track these message IDs in sets and 
other Java data structures.
   
   It appears that the client library intends for these two types to be treated 
the same from the user's perspective if they refer to the same topic, as 
`BatchMessageIdImpl` tries to make `equals` work with `MessageIdImpl` 
instances. Unfortunately `hashCode` is not consistent with `equals` there, 
because `MessageIdImpl` does not take into account the batch index of `-1`.
   
   Also, the `equals` relationship `TopicMessageIdImpl` and `MessageIdImpl` 
instances is not symmetric: `messageIdImpl.equals(topicMessageIdImpl)` will 
return `true` as long as the inner message ID is equal, while 
`topicMessageIdImpl.equals(messageIdImpl)` will not, as the `equals` method of 
`TopicMessageIdImpl` returns `false` for instances that are not of the same 
type.
   
   **Expected behavior**
   
   `equals` and `hashCode` methods follow the their respective contracts.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to