Skip to content

Repeated @Size on a List generates no adapter (No Constraints Defined warning, then IllegalArgumentException) #385

Description

@ah3nan

Applying the same constraint annotation twice to one field silently produces no adapter. The
processor warns, and validation then throws at runtime.

Reproduction

@Valid
record Two(@Size(min = 1) @Size(max = 5) List<String> x) {}

Validator.instance().validate(new Two(List.of()));

Compile output

warning: No Constraints Defined
    record Two(@Size(min = 1) @Size(max = 5) List<String> x) {}

No TwoValidationAdapter is generated.

Runtime

java.lang.IllegalArgumentException: No ValidationAdapter for class v.V2$Same
    at io.avaje.validation.core.CoreAdapterBuilder.buildForType(CoreAdapterBuilder.java:83)
    at io.avaje.validation.core.CoreAdapterBuilder.build(CoreAdapterBuilder.java:60)
    at io.avaje.validation.core.DValidator.adapter(DValidator.java:151)

Notes

  • A single @Size on the same field works and reports the violation.
  • @NotBlank @Size on a String works; repeating @NotBlank @NotBlank does not even compile
    (NotBlank is not a repeatable annotation interface), so @Size is the case where repetition is
    accepted by the compiler but not handled by the generator.
  • Hibernate Validator 9.1.2 validates the repeated form (@Size(min=1) @Size(max=5) on a List)
    and reports the violation.

Expected

Either support repeated constraints on the same element, or reject them at build time with an error
rather than emitting a warning and no adapter (the failure currently surfaces only at runtime).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions