Search code examples
validationsize

CPU Usage Increases Because Spring Boot Uses the Validation @Size Annotation to Verify Lists


I validate the List size using java validation @Size:

@RestController
@RequestMapping(value = "/", produces = {"application/json;charset=UTF-8"})
@Validated
public class TestController {

    @RequestMapping(
            value = "/test", 
            method = RequestMethod.POST)
    public void addResource(
            @Valid 
        **@Size(min=1,max=3)**
            @Valid @RequestBody List<TestDTO> testList)  {
           .....
        
    }
}

when I send a request and list size is huge (about 700000), then the cpu usage is 100%. how I resolve it ? Is it a @Size bug?

the request body (700000 []):

[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},.......
.......
.......
.......
]

I use springBoot3, jakarta.validation-api:3.0.2

I try to limit size of request body, Is there any other solution?


Solution

  • It is my code bug in my custom message trace filter.