Hi,
Description: - Using Spring boot version 1.5.9 - Added Validation of request params with @max annotation. [PFB Test Code] - When given request using postman getting no message available & on console getting error message as:
o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is javax.validation.ConstraintViolationException] with root cause
javax.validation.ConstraintViolationException: null
Test code:
@RestController
@Validated
@RequestMapping("/api")
public class WelcomeController {
@RequestMapping(value = "/testinfo", method = RequestMethod.GET)
public ResponseEntity testInfo(@RequestParam(value = "id", defaultValue = "")
@Max(value=4,message="Should be less than 4") Integer id)
{
Map<String, Object> map = new LinkedHashMap<>();
map.put("id", id);
return ResponseEntity.status(HttpStatus.OK).body(map);
}
}
Postman Output:
{
"timestamp": 1543474224967,
"status": 500,
"error": "Internal Server Error",
"exception": "javax.validation.ConstraintViolationException",
"message": "No message available",
"path": "/api/testinfo"
}
Problem: Here i am not able to see the message "Should be less than 4", instead it is null in console output.
What could be the problem ? Am i missing anything here ?
Comment From: wilkinsona
Thanks for the report, but the code in question is part of Spring Framework and the Bean Validation API. Spring Framework creates a ConstraintViolationException with no message and the set of violations. When ConstraintViolationException is created with only a set of violations, it uses null for its message.
Comment From: alixiaodi
@wilkinsona Has this problem been solved? Even if I added it, it still doesn't work
Comment From: wilkinsona
@alixiaodi I'm not sure what you mean by "added it", but I can say that the code in Spring Framework continues to create a ConstraintViolationException with no message and a set of violations. Note that this is all out of Spring Boot's control as the functionality in question is part of Spring Framework and the Bean Validation API. If you have any further questions, please follow up in the appropriate place.