Find fields and parameters of constrained types missing @Valid
ProprietaryMarks a field or parameter whose type declares or inherits Bean Validation constraints, such as @NotNull on one of its fields or getters, or a field or getter annotated @Valid of such a type, but which is not annotated @Valid, where validation would otherwise reach it: a field or record component of a class that validation reaches, as the type of something annotated @Valid elsewhere in the repository, a JPA @Entity, a Spring @ConfigurationProperties class annotated @Validated, or a superclass or interface of one, and a parameter annotated @RequestBody, @RequestPart or @ModelAttribute, or another argument of a Spring MVC handler method followed by Errors or BindingResult, other than a collection outside a class Spring validates, the entity parameter of a JAX-RS @POST, @PUT or @PATCH method, or a parameter of a public method, other than a final or @Autowired, @Inject or @Resource one, of a non-final class Spring validates, one that is or extends a @Validated type and is not a @ConfigurationProperties class, or of an interface or superclass of such a class, or of a Spring MVC handler or JAX-RS resource method that declares a constraint or @Valid elsewhere, unless another Spring annotation such as @PathVariable or @AuthenticationPrincipal binds it. Without @Valid, validation does not cascade into it, and its constraints go unchecked. For a container such as List<Order> or an Optional, the type arguments are checked, for a Map only the value type, and List<@Valid Order> counts as annotated. Both jakarta.validation and javax.validation are recognized, and a parameter annotated with Spring's @Validated counts as annotated. A parameter of a method that may override another, as a superclass or interface declares a method with the same name and number of parameters or is missing from the sources and dependencies, is not marked: @Valid belongs on the topmost declaration, and Hibernate Validator rejects it on an override. Nor is a parameter of a method that two unrelated supertypes of a class Spring validates both declare, as Hibernate Validator rejects @Valid on either. JPA and Spring Data associations, arrays, static fields and methods, private methods, constructors, members of anonymous classes, ConstraintValidator implementations and HTTP clients such as a @FeignClient or @HttpExchange interface are not marked. Adding @Valid turns on validation that may reject input accepted today, so it is left to the author. Test sources are not searched.
io. moderne. staticanalysis. FindMissingValidAnnotationmod run . --recipe= io. moderne. staticanalysis. FindMissingValidAnnotationInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.