spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.6k stars 38.13k forks source link

`@RequestParam` throws `java.lang.NullPointerException: The mapper returned a null value.` [SPR-17050] #21588

Closed spring-projects-issues closed 6 years ago

spring-projects-issues commented 6 years ago

Kamil Bar opened SPR-17050 and commented

The reactive controller method with request parameter fails with 

java.lang.NullPointerException: The mapper returned a null value.

and returns HTTP 500 instead of the HTTP 400 with some conversion error message when called with empty parameter value, i.e. 

integer?parameter=

or

boolean?parameter=

 

I've pushed sample project using spring-boot 2.0.3.RELEASE with failing JUnit 5 tests for integer and boolean types of parameter and one successful test with string type parameter.

I've posted this bug also on spring-boot issue tracker https://github.com/spring-projects/spring-boot/issues/13786 but was redirected here.


Affects: 5.0.7

Reference URL: https://github.com/NeveHanter/spring_boot_request_param_bug

3 votes, 3 watchers

spring-projects-issues commented 6 years ago

Brian Clozel commented

NeveHanter,

Thanks a lot for this issue and the repro case (this is always very useful and it's worth many comments).

I've just pushed a fix which should be available shortly with Spring Framework 5.0.8 and 5.1.0 snapshots (i.e. Spring Boot 2.0.4 and 2.1.0 snapshots).

Note that in your sample, not providing a @RequestParam annotation on the arguments is the equivalent of not requiring the request param - in that case, the handler won't respond with a HTTP 400, but a 200 OK.

I've added the @RequestParam annotation on the various parameters and tested your sample with Spring Boot 2.1.0 and things are working as expected.