Lombok: [BUG] Other handling of custom javax validations since 1.18.10

Created on 4 Nov 2019  ·  4Comments  ·  Source: projectlombok/lombok

After Increasing the lombok version from 1.18.8 to 1.18.10 one Junit test doesn't work anymore which tests the javax validation.

In the test, following exception is thrown:
javax.validation.ValidationException: HV000187: When using type annotation constraints on parameterized iterables or map @Valid must be used.

I could find out, that the problem is our custom annotation "NotNullEntry"

In the Test an object is tested which has following annotation. In the Test, the object is just created as an new instance not with the lombok builder.

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.Valid;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ClassX {

  @Valid
  private List<@NotNullEntry SomeType> objects;
}

NotNullEntry is a custom annotation and is defined like following:

import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.constraints.NotNull;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@NotNull
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {})
public @interface NotNullEntry {

  String message() default
      "";

  Class<?>[] groups() default {};

  Class<? extends Payload>[] payload() default {};
}

Further Details:
Lombok Version: 1.18.10
IDE: Intellij 20019.2.4
Lombok Plugin Version: 0.27-2019.2

The Test:

@Test
  public void shouldCreateViolationForNotValidList() {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    Set<ConstraintViolation<TechnicalInformationJson>> result = validator
        .validate(new ClassX());

    assertThat(result.size(), is(1));
  }

Most helpful comment

I encountered the same problem!

All 4 comments

I encountered the same problem!

Seems to be still an issue, probably happened when I moved from @Wither to @With

any chances to get it fixed?

It looks like @Valid has to be present on the generated methods. Can you try to add lombok.copyableAnnotations += javax.validation.Valid to your lombok.config?

Was this page helpful?
0 / 5 - 0 ratings