On Tue, 11 Nov 2025 17:10:34 GMT, Patrick Strawderman <[email protected]> wrote:

> That wouldn't help with the `stream().sorted(Comparator.naturalOrder())` 
> case; the example I supplied is somewhat contrived, I originally ran into 
> this in Guava (see the [issue](https://github.com/google/guava/issues/6187) I 
> opened there); the library is null-hostile and so always supplies a 
> comparator to its sorted collections. 

If you switch from Comparator.naturalOrder()) to null, you have to do it in 
stream.sorted() too (and also List.sort(Comparator), 
Collections.sort(Comparator), Array.sort(Comparator), 
Collections.reverseOrder(Comparator) etc)

> Note that this won't directly fix the issue there until they move away from 
> their custom natural order comparator to the one from the JDK.

yes, comparing comparators with == is brittle anyway, but at least you can make 
it consistent for the JDK.

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

PR Comment: https://git.openjdk.org/jdk/pull/28226#issuecomment-3518051371

Reply via email to