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] Duplicate @Valid constraint validation on @Data class after update from 1.18.22 to 1.18.24 #3304

Closed
dballardgh opened this issue Nov 24, 2022 · 4 comments

Comments

@dballardgh
Copy link

Describe the bug
A Lombok 1.18.24 @Data class that is validated using Hibernate's hibernate-validator results in constraints such as @NotNull being validated twice. This doesn't happen with 1.18.22 or earlier versions.

To Reproduce
I don't have a standalone test case yet. Working on it. In a nutshell:

Given @Data class:

@Data
public class MyForm {
  @NotNull(message="Please specify a name")
  private String name;
}

And a Spring MVC endpoint:

  @PostMapping("/my-endpoint")
  public String save(@ModelAttribute("form") @Valid MyForm form,
                     BindingResult bindingResult, Map<String, Object>  model,
                     HttpServletRequest request, final RedirectAttributes redirectAttributes) {}

When a request is POSTed without a name:

Expected behavior
Then I expect bindingResult to contain one error for field name with message Please specify a name.

Actual behavior
The bindingResult contains two errors for field name with message Please specify a name.

Version info (please complete the following information):

  • Lombok version 1.18.24
  • Spring MVC 5.3.24
  • Hibernate validator 5.4.3.Final
  • javac 17.0.3

Additional context
I suspect, but I'm not sure yet, that property name and getter getName() are being validated with 1.18.24, but earlier versions are only validating one of them.

@dballardgh
Copy link
Author

Sorry for the delay. Looks like in 1.18.24, lombok takes the @NotNull and applies it to the property setter. This doesn't happen in prior versions.

When I delombok the source with 1.18.22 I see:

public class MyForm {
  @NotNull(message = "Please specify a name")
  private String name;

  @java.lang.SuppressWarnings("all")
  public MyForm() {
  }

  @java.lang.SuppressWarnings("all")
  public String getName() {
    return this.name;
  }

  @java.lang.SuppressWarnings("all")
  public void setName(final String name) {
    this.name = name;
  }
  // ...
}

With 1.18.24 I see:

public class MyForm {
  @NotNull(message = "Please specify a name")
  private String name;

  @java.lang.SuppressWarnings("all")
  public MyForm() {
  }

  @NotNull(message = "Please specify a name")
  @java.lang.SuppressWarnings("all")
  public String getName() {
    return this.name;
  }

  @java.lang.SuppressWarnings("all")
  public void setName(@NotNull(message = "Please specify a name") final String name) {
    this.name = name;
  }
  // ...
}

@mistic100
Copy link

I confirm the issue since javax.validation.constraints.NotNull was added to the copiable annotations here #2904

The "IMPROBABLE BREAKING CHANGE" mention in the changelog made me chuckle

@mistic100
Copy link

@dballardgh If you are interrested, the discussion on issue #3180 has more info about this

@Rawi01
Copy link
Collaborator

Rawi01 commented Feb 12, 2023

This change was reverted in 1473389 which is part of 1.18.26.

@Rawi01 Rawi01 closed this as completed Feb 12, 2023
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

3 participants