Skip to content

Improve type safety of CollectionUtils.toTreeSet#16306

Open
skt-shinyruo wants to merge 1 commit into
apache:3.3from
skt-shinyruo:fix-16297-collection-utils-to-tree-set
Open

Improve type safety of CollectionUtils.toTreeSet#16306
skt-shinyruo wants to merge 1 commit into
apache:3.3from
skt-shinyruo:fix-16297-collection-utils-to-tree-set

Conversation

@skt-shinyruo
Copy link
Copy Markdown

What is the purpose of the change?

GitHub_issue: Fixes #16297

This pull request improves the type safety of CollectionUtils.toTreeSet.

The existing single-argument overload accepted any Set<T>, but its implementation delegates to TreeSet, which requires naturally comparable elements unless a comparator is provided. The updated signature makes that requirement explicit at compile time:

public static <T extends Comparable<? super T>> Set<T> toTreeSet(Set<T> set)

This pull request also adds a comparator-based overload for custom ordering and non-Comparable element types:

public static <T> Set<T> toTreeSet(Set<T> set, Comparator<? super T> comparator)

For non-null empty inputs, the comparator overload returns an empty TreeSet that preserves the provided comparator.

Verification:

  • mvn -pl dubbo-common -Dtest=CollectionUtilsTest test
  • git diff --check

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 2, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.77%. Comparing base (b65573e) to head (a5a64f9).

Files with missing lines Patch % Lines
...org/apache/dubbo/common/utils/CollectionUtils.java 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16306      +/-   ##
============================================
- Coverage     60.80%   60.77%   -0.04%     
+ Complexity    11766    11764       -2     
============================================
  Files          1953     1953              
  Lines         89188    89193       +5     
  Branches      13454    13454              
============================================
- Hits          54235    54209      -26     
- Misses        29391    29410      +19     
- Partials       5562     5574      +12     
Flag Coverage Δ
integration-tests-java21 32.16% <0.00%> (+0.04%) ⬆️
integration-tests-java8 32.24% <0.00%> (+<0.01%) ⬆️
samples-tests-java21 32.17% <0.00%> (-0.02%) ⬇️
samples-tests-java8 29.86% <0.00%> (+<0.01%) ⬆️
unit-tests-java11 59.01% <60.00%> (-0.05%) ⬇️
unit-tests-java17 58.49% <60.00%> (-0.05%) ⬇️
unit-tests-java21 58.53% <60.00%> (+0.04%) ⬆️
unit-tests-java25 58.46% <60.00%> (-0.02%) ⬇️
unit-tests-java8 59.03% <60.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@zrlw zrlw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Improve type safety of CollectionUtils.toTreeSet

3 participants