Pre-check
Search before asking
Apache Dubbo Component
Java SDK (apache/dubbo)
Dubbo Version
Dubbo - 3.3, JDK - 21, OS - MacOS(26.3.1 (a) (25D771280a))
Steps to reproduce this issue
Improve generic type safety of CollectionUtils.sort
What you expected to happen
Motivation
CollectionUtils.sort currently accepts any List<T> and internally calls Collections.sort using a raw cast / suppressed warnings.
This allows code like CollectionUtils.sort(List<NonComparableType>) to compile, but it may fail at runtime because natural ordering requires elements to implement Comparable.
Proposed change
Change the method signature from:
public static <T> List<T> sort(List<T> list)
to
public static <T extends Comparable<? super T>> List<T> sort(List<T> list)
and remove the raw cast
Anything else
This aligns the method with java.util.Collections.sort, improves compile-time type safety, and preserves the original return type List.
Do you have a (mini) reproduction demo?
Are you willing to submit a pull request to fix on your own?
Code of Conduct
Pre-check
Search before asking
Apache Dubbo Component
Java SDK (apache/dubbo)
Dubbo Version
Dubbo - 3.3, JDK - 21, OS - MacOS(26.3.1 (a) (25D771280a))
Steps to reproduce this issue
Improve generic type safety of CollectionUtils.sort
What you expected to happen
Motivation
CollectionUtils.sortcurrently accepts anyList<T>and internally callsCollections.sortusing a raw cast / suppressed warnings.This allows code like
CollectionUtils.sort(List<NonComparableType>)to compile, but it may fail at runtime because natural ordering requires elements to implementComparable.Proposed change
Change the method signature from:
to
and remove the raw cast
Anything else
This aligns the method with java.util.Collections.sort, improves compile-time type safety, and preserves the original return type List.
Do you have a (mini) reproduction demo?
Are you willing to submit a pull request to fix on your own?
Code of Conduct