## Summary

[`JDK-8223933`](https://bugs.openjdk.org/browse/JDK-8223933)

`Stream.distinct()` must remove duplicates according to `Object.equals`. On 
sorted streams it only compared each element to the previous one, which fails 
when `compareTo` is inconsistent with `equals`, so duplicates can still be 
emitted.

## Fix
Keep the sorted-path consecutive check, and also track emitted elements in a 
`HashSet` so uniqueness always follows `equals`. Add a regression test for the 
reported case and for equals-duplicates in different sort groups.

---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

-------------

Commit messages:
 - 8223933: Stream.distinct() on sorted streams must respect Object.equals

Changes: https://git.openjdk.org/jdk/pull/32670/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=32670&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8223933
  Stats: 179 lines in 2 files changed: 176 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/32670.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/32670/head:pull/32670

PR: https://git.openjdk.org/jdk/pull/32670

Reply via email to