-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][misc] Fix compareTo contract violation for NamespaceBundleStats, TimeAverageMessageData and ResourceUnitRanking #24772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix][misc] Fix compareTo contract violation for NamespaceBundleStats, TimeAverageMessageData and ResourceUnitRanking #24772
Conversation
…sageData - JVM's default sorting algorithm "TimSort" will fail with exception if compareTo doesn't meet the contract of Comparable.compareTo interface
…atifying the contract
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #24772 +/- ##
=============================================
+ Coverage 39.04% 74.23% +35.18%
- Complexity 13345 33248 +19903
=============================================
Files 1844 1902 +58
Lines 144311 148392 +4081
Branches 16730 17201 +471
=============================================
+ Hits 56353 110158 +53805
+ Misses 80460 29444 -51016
- Partials 7498 8790 +1292
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…, TimeAverageMessageData and ResourceUnitRanking (#24772)
…, TimeAverageMessageData and ResourceUnitRanking (#24772)
|
After merging, I noticed that NamespaceBundleStats uses a slightly different implementation for |
…, TimeAverageMessageData and ResourceUnitRanking (apache#24772) (cherry picked from commit 7504538) (cherry picked from commit ae9be46)
…, TimeAverageMessageData and ResourceUnitRanking (apache#24772) (cherry picked from commit 7504538) (cherry picked from commit ae9be46)
…, TimeAverageMessageData and ResourceUnitRanking (apache#24772) (cherry picked from commit d6b00f9)
…, TimeAverageMessageData and ResourceUnitRanking (apache#24772) (cherry picked from commit d6b00f9)
…, TimeAverageMessageData and ResourceUnitRanking (apache#24772)
…, TimeAverageMessageData and ResourceUnitRanking (apache#24772) (cherry picked from commit 7504538)
Fixes #24754
Motivation
java.lang.IllegalArgumentException: Comparison method violates its general contract!ifcompareTodoesn't meet the contract ofComparable.compareTointerfaceThe contract of
Comparable.compareTo:The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)
The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.
Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.
Modifications
Comparable.compareTocontract by using a difference.compareTofor NamespaceBundleStats and TimeAverageMessageDatacompareTomethod tocompareToOtherRankingand remove theComparableinterface since ResourceUnitRanking cannot fulfill the contract and there isn't a need to do so. Removing the interface and new comments in thecompareToOtherRankingmethod will help prevent possible misuse later. The current usage of ResourceUnitRanking's method is fine, it's just not requiring Comparable.compareTo semantics and contract. That's why it's better to rename the method.Documentation
docdoc-requireddoc-not-neededdoc-complete