Skip to content
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

MimeType compareTo implementation is not compatible with equals [SPR-16458] #21003

Closed
spring-projects-issues opened this issue Feb 2, 2018 · 3 comments
Assignees
Labels
status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 2, 2018

Aliaksandr Kazlou opened SPR-16458 and commented

Not sure, it this is by design or a bug. But in the MimeType::equals there is a special check for the charset parameter, i.e.

if (PARAM_CHARSET.equals(key)) {
				if (!ObjectUtils.nullSafeEquals(getCharset(), other.getCharset())) {
					return false;
				}
			}

While in the MimeType::compareTo method it doesn't handle charset parameter any how specific, so simple string comparison is done then.

So, the possible issue is that equals will produce true when comparing application/json;charset=UTF-8 and application/json;charset=utf-8, while compareTo will return "false".


Affects: 4.3.14, 5.0.3

Issue Links:

Backported to: 4.3.15

@spring-projects-issues
Copy link
Collaborator Author

Aliaksandr Kazlou commented

Another consequence of this if using Spock framework and verifying the content type in Groovy, and there is a known issue in Groovy if the class implements compareTo it will be used instead of equals when using == operator. And I faced that problem when upgrading to the latest Spring Boot 1.5.9 from Spring Boot 1.3.2, not sure where exactly the change happens, but in the Spring Boot 1.3.2 content type in the response was set to application/json;charset=UTF-8, while with the latest Spring Boot (I assume related to the upgrade to the Apache HttpComponent as well) it now returns application/json;charset=utf-8 in the response.

Or is it related to the @SpringBootTest or new implementation of the TestRestTemplate? Could not find where the conversion to lower case happens.

Any ideas on this?

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 2, 2018

Juergen Hoeller commented

This behavior got introduced in Spring Framework 4.2 through #17748. I've revised the MimeType.compareTo implementation to follow the same rules as equals now, so hopefully all such problems will be gone for good now.

Committed to master for 5.0.4; to be backported to 4.3.15 next week.

@spring-projects-issues
Copy link
Collaborator Author

Aliaksandr Kazlou commented

It could be related actually to the Jetty version update as mentioned in the linked ticket https://bugs.eclipse.org/bugs/show_bug.cgi?id=414449, although not clear whether it is indeed the case.

At least migration from Spring Boot 1.3.2 to Spring Boot 1.5.9 update the Jetty from 9.2.14.v20151106 to 9.4.7.v20170914, so I believe a lot could happen in between.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants