Skip to content

[Regression] 404 without ACCEPT request header results in a 406 in Spring Framework 5.1.6 #22853

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

Closed
mixcloud-downloader opened this issue Apr 29, 2019 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Milestone

Comments

@mixcloud-downloader
Copy link

mixcloud-downloader commented Apr 29, 2019

Affects: 5.1.6

Since the Upgrade from Spring-Boot-2.1.3.RELEASE to Spring-Boot-2.1.4.RELEASE, any error (e.g. a 404 or an 500) an expected 404 without an ACCEPT request header result in a 406 response and this message in the logs:

DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]

This regression happens only when setting the default content type to TEXT_HTML:

@Configuration
class DefaultContentTypeConfiguration implements WebMvcConfigurer {

	@Override
	public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
		configurer.defaultContentType(TEXT_HTML);
	}
}

See spring-attic/spring-framework-issues#191 for an example.

On a site note: This is the second bug in a very short time (the other was #22851) which goes unnoticed with Spring's classic MockMVC testing approach. It makes me thing that using MockMVC is not a too good idea any more.

@mixcloud-downloader mixcloud-downloader changed the title [Regression] Since Spring-Boot-2.1.4.RELEASE errors wiithout ACCEPT header result in a 406 [Regression] Since Spring-Boot-2.1.4.RELEASE errors without ACCEPT header result in a 406 Apr 29, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 29, 2019
mixcloud-downloader added a commit to mixcloud-downloader/spring-framework-issues that referenced this issue Apr 29, 2019
@mixcloud-downloader mixcloud-downloader changed the title [Regression] Since Spring-Boot-2.1.4.RELEASE errors without ACCEPT header result in a 406 [Regression] Since Spring-Boot-2.1.4.RELEASE 404 without ACCEPT request header result in a 406 Apr 29, 2019
@jhoeller jhoeller added the type: regression A bug that is also a regression label Apr 30, 2019
@jhoeller jhoeller added this to the 5.1.7 milestone Apr 30, 2019
rstoyanchev pushed a commit to spring-attic/spring-framework-issues that referenced this issue Apr 30, 2019
@rstoyanchev rstoyanchev self-assigned this Apr 30, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 30, 2019
@rstoyanchev
Copy link
Contributor

This appears to be related to the changes for #22598. An empty ProducesRequestCondition returns a constant EMPTY_CONDITION instead of this which causes it to lose the configured ContentNegotiationManager, which in Spring Boot falls back on "text/html" by default.

@rstoyanchev rstoyanchev changed the title [Regression] Since Spring-Boot-2.1.4.RELEASE 404 without ACCEPT request header result in a 406 [Regression] 404 without ACCEPT request header results in a 406 in Spring Framework 5.1.6 May 1, 2019
@mixcloud-downloader
Copy link
Author

Thanks for addressing that issue.

I have a small question regarding this. I try to add a test to my application which would basically do the same as in the referenced example, i.e. make a request against a non existing URI and check the response code. Now, locally the test works as expected (fails with 406 in Spring-Boot-2.1.4 and succeeds with 404 in Spring-Boot-2.1.3). But for whatever reason when I let it run in GitLab's CI (which is the maven:3-jdk-11 docker image) the test even succeeds with a 404 with the broken Spring-Boot-2.1.4. Do you by any chance have any idea why it could succeed?

@rstoyanchev
Copy link
Contributor

The issue was related to comparing two error handling methods and ignoring the "text/html" default content type preference. It's possible the two methods were ordered differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants