Dhairya-007 opened a new pull request, #29569:
URL: https://github.com/apache/camel/pull/29569
`NowSearchTerm` extends `jakarta.mail.search.ComparisonTerm`, which declares
```java
protected int comparison;
public boolean equals(Object obj) { ... return ct.comparison ==
this.comparison; }
public int hashCode() { return comparison; }
```
but it redeclares the same field itself:
```java
private final int comparison; // shadows ComparisonTerm.comparison
```
So `this.comparison = comparison` in the constructor assigns the *subclass*
field and the inherited one stays `0` for every instance. `super.equals(o)`
therefore compares `0 == 0` and always passes, which leaves `equals` testing
nothing but `sentDate` — while `hashCode()` returns the subclass `comparison`,
which does vary. Two terms that differ in `comparison` or in `offset` are
reported equal but hash differently, so the equals/hashCode contract is broken
in the direction that matters: equal objects land in different hash buckets.
`offset` was not part of either method, so "sent within the last 24 hours"
(`GE`, offset `-86400000`) and "sent before now" (`LT`, offset `0`) were
`equals`.
Fix: drop the shadowing field so the inherited `comparison` is the one
assigned and compared (this is what jakarta.mail's own subclasses such as
`DateTerm` and `IntegerComparisonTerm` do), and include `offset` in both
methods, following `DateTerm`'s idiom of combining `super`.
`match()` reads `comparison` unchanged — same value, now from the inherited
field.
Verified with a standalone replica (no Maven available here), the
`ComparisonTerm` semantics copied from the Jakarta Mail API and the old bodies
copied verbatim from this file:
```
BEFORE inherited comparison field: 0 (never assigned)
BEFORE (cmp=6,sent=true,off=-86400000).equals(cmp=2,sent=true,off=0) = true
hashCodes 6 vs 2
BEFORE HashSet size with two 'equal' terms = 2 (contract broken)
AFTER (cmp=6,sent=true,off=-86400000).equals(cmp=2,sent=true,off=0) = false
AFTER equal copies: equals=true sameHash=true
AFTER HashSet size for {t, copy-of-t, other} = 2
```
The terms are built by `SearchTermBuilder` and `MailConverters` for the mail
consumer's `searchTerm` option; no call site depends on the old behaviour.
--
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]