Skip to content

MockHttpServletResponse setIntHeader throws Exception when passed an int value for 'Content-length' [SPR-14016] #18588

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
spring-projects-issues opened this issue Mar 3, 2016 · 2 comments
Assignees
Labels
in: test Issues in the test module status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 3, 2016

Chris Tosspon opened SPR-14016 and commented

Using Spring 4.1.8.RELEASE, testing a controller method with a response.setIntHeader('Content-length', 5) throws the following Exception

java.lang.Integer cannot be cast to java.lang.String
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
	at org.springframework.mock.web.MockHttpServletResponse.setSpecialHeader(MockHttpServletResponse.java:513)

As it seems to be a valid use case to manually set a Content-length header with an integer, the cast of the Object value to String type inside the setSpecialHeader method should be conditional.

setContentLength(Integer.parseInt((String) value));

I have supplied a referenceURL with an example app/test case that shows the unexpected behavior. It's a gradle/grails project that can be run with ./gradlew test


Affects: 4.1.8

Reference URL: https://github.com/cTwospoons/mock-http-response-int-header-exception

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Mar 3, 2016

Juergen Hoeller commented

This is a duplicate of #18325 which has been fixed for 4.2.4 and 4.1.9 already.

@spring-projects-issues
Copy link
Collaborator Author

Chris Tosspon commented

Sorry for the duplicate issue. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants