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

Lombok version in 2.6.7 breaks code #30777

Closed
Hayo-Baan opened this issue Apr 23, 2022 · 3 comments
Closed

Lombok version in 2.6.7 breaks code #30777

Hayo-Baan opened this issue Apr 23, 2022 · 3 comments
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid

Comments

@Hayo-Baan
Copy link

With Spring Boot 2.6.7 you also updated the version of lombok. This version of Lombok propagates (some of) the field annotations to the generated getters and setters. This is not always valid/desired and actually leads to valid code breaking (at runtime).

Simple case:

public interface BaseEntityDto {

    /**
     * Returns the ID of the entity.
     *
     * @return the ID of the entity.
     */
    Long getId();

    /**
     * Sets the ID of the entity.
     *
     * @param id the ID of the entity.
     */
    void setId(Long id);

    /**
     * Returns the timestamp of the last update of the entity.
     *
     * @return the timestamp of the last update.
     */
    Instant getUpdateTimestamp();

    /**
     * Sets the timestamp of the last update of the entity.
     *
     * @param updateTimestamp the timestamp of the last update.
     */
    void setUpdateTimestamp(Instant updateTimestamp);

    /**
     * Returns the version of the entity.
     *
     * @return the version of the entity.
     */
    Long getVersion();

    /**
     * Sets the version of the entity.
     *
     * @param version the version of the entity.
     */
    void setVersion(Long version);

}

@Data
public class AccountDto implements BaseEntityDto {

    /**
     * Interface for annotating the validation group for account creation.
     */
    public interface CreateValidation {}

    @Null(groups = CreateValidation.class)
    @NotNull
    @Positive
    private Long id;

    @NotBlank(groups = {Default.class, CreateValidation.class})
    private String name;

    private Instant updateTimestamp;

    @NotNull
    @Null(groups = CreateValidation.class)
    private Long version;
}

Here for example, the setter (and getter) of ID get annotated with @NotNull. However this is a perfectly valid (actually mandatory) value when the AccountDto object is validated with CreateValidation. Moreover, at runtime you get an javax.validation.ConstraintDeclarationException - HV000151: A method overriding another method must not redefine the parameter constraint configuration exception as the interface defines no constraints, but the implementation now does.

Adding the constraint to the interface is no solution as for one class of objects I might need different object validation than for another while they still inherit from the BaseEnityDto interface. Besides, I want just the end-state of the object validated (and then depending on the applicable validation group), not the intermediate states!

I've raised this issue also with Lombok: projectlombok/lombok#3180

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 23, 2022
@snicoll
Copy link
Member

snicoll commented Apr 23, 2022

Thanks but there's no need to raise this again here. If you are affected, you can downgrade lombok as documented in the reference guide using the lombok.version property.

@snicoll snicoll closed this as completed Apr 23, 2022
@snicoll snicoll added status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 23, 2022
@Hayo-Baan
Copy link
Author

Hi @snicoll, agreed, this issue should be tracked at Lombok. My reason for raising it here too is to inform others that might stumble on this same issue and look here first (it's what I did, before going to the Lombok site…).

@jmsjr
Copy link

jmsjr commented Apr 30, 2022

The lombok point release from 1.18.22 to 1.18.24 is a bit of a mess ( with tempers flaring I might add ) as it is a breaking change that I did not know was the root cause as I myself thought that since hibernate-validator remained the same between springboot 2.6.6 and 2.6.7, it can't be anything to do with hibernate-validator ... until someone at stackoverflow pointed to me that it is the lombok change that came with springboot 2.6.7.

Anyway, it appears that lombok maintainers may ( or may not ? ) release 1.18.26 with the previous behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants