Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Other handling of custom javax validations since 1.18.10 #2282

Open
Kusarr opened this issue Nov 4, 2019 · 8 comments
Open

[BUG] Other handling of custom javax validations since 1.18.10 #2282

Kusarr opened this issue Nov 4, 2019 · 8 comments

Comments

@Kusarr
Copy link

Kusarr commented Nov 4, 2019

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));
  }
@good2luck
Copy link

I encountered the same problem!

@dearlordylord
Copy link

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

@mslowiak
Copy link

any chances to get it fixed?

@Rawi01
Copy link
Collaborator

Rawi01 commented Jan 25, 2021

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?

@vishal-ab
Copy link

Same issue for me, did anyone find out the solution?

@mako-taco
Copy link

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?

This does not appear to solve the issue.

@phantasmicmeans
Copy link

If you use intelij IDEA, change the java sdk setting to 11

After the version up, I have no issue.

image

@nicolaibocearov85
Copy link

This worked for me

@Getter(onMethod = @__(@Valid))
@Setter(onParam = @__(@Valid))
@Valid

not only I had to put @Valid on getter and setter methods but on the class member as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants