-
Notifications
You must be signed in to change notification settings - Fork 38.5k
MediaType.sortBySpecificityAndQuality throws java.lang.IllegalArgumentException: Comparison method violates its general contract #27488
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
Milestone
Comments
poutsma
added a commit
to poutsma/spring-framework
that referenced
this issue
Oct 20, 2021
This commit makes several changes to MimeType and MediaType related to the topic of specificity. This commit deprecates the MimeType and MediaType Comparators. Comparators require a transitive relationship, and the desired order for these types is not transitive (see spring-projects#27488). Instead, this commit introduces two new MimeType methods: isMoreSpecific and isLessSpecific, both of which return booleans. MediaType overrides these methods to include the quality factor (q) in the comparison. All MediaType sorting methods have been deprecated in favor of MimeTypeUtils::sortBySpecificity. This sorting method now uses MimeType::isLessSpecific in combination a bubble sort algorithm (which does not require a transitive compare function). Closes spring-projectsgh-27580
poutsma
added a commit
that referenced
this issue
Nov 23, 2021
This commit makes several changes to MimeType and MediaType related to the topic of specificity. This commit deprecates the MimeType and MediaType Comparators. Comparators require a transitive relationship, and the desired order for these types is not transitive (see #27488). Instead, this commit introduces two new MimeType methods: isMoreSpecific and isLessSpecific, both of which return booleans. MediaType overrides these methods to include the quality factor (q) in the comparison. All MediaType sorting methods have been deprecated in favor of MimeTypeUtils::sortBySpecificity. This sorting method now uses MimeType::isLessSpecific in combination a bubble sort algorithm (which does not require a transitive compare function). Closes gh-27580
I met the same question in spring 5.3.13, what can I do? |
Upgrade to 6.0. As you can read above, we could not fix this without breaking backward compatibility, so a 5.3.x fix is not forthcoming. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Affects: spring-web:5.3.9
Original Problem from stackoverflow
Implementation of QUALITY_VALUE_COMPARATOR seems violate general contract of comparator.
The issue can be reproduced by below program.
OS: Window 10
JDK: openjdk version "16" 2021-03-16
The text was updated successfully, but these errors were encountered: