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: https://github.com/projectlombok/lombok/issues/3180
Comment From: snicoll
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.
Comment From: Hayo-Baan
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…).
Comment From: jmsjr
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.