You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have problems with the newly added @Builder.Default in v1.16.18.
It changes the behaviour of manual created constructors. It will leed to ignore default values of attributes (like private String b = "b";) if annotated with @Builder.Default . I reduced this issue to the following two classes and test case which shows my expectations.
classes:
public class Lombok {
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class WithBuilderDefaultAnnotation {
private String a;
@Builder.Default
private String b = "b";
public WithBuilderDefaultAnnotation(String a) {
this.a = a;
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class WithoutBuilderDefaultAnnotation {
private String a;
private String b = "b";
public WithoutBuilderDefaultAnnotation(String a) {
this.a = a;
}
}
}
unit tests:
public class LombokTest {
/** SUCCESSFUL, entity.getB() returns "b" */
@Test
public void testA() {
Lombok.WithoutBuilderDefaultAnnotation entity = new Lombok.WithoutBuilderDefaultAnnotation("hello world");
assertEquals("b", entity.getB());
}
/** FAILS, entity.getB() returns null */
@Test
public void testB() {
Lombok.WithBuilderDefaultAnnotation entity = new Lombok.WithBuilderDefaultAnnotation("hello world");
assertEquals("b", entity.getB());
}
/** SUCCESSFUL, entity.getB() returns null as expected because Lombok.Working has NO {@link lombok.Builder.Default} annotation (maybe this would be the default behaviour later in Lombok?) */
@Test
public void testC() {
Lombok.WithoutBuilderDefaultAnnotation entity = Lombok.WithoutBuilderDefaultAnnotation.builder().a("hello world").build();
assertNull(entity.getB());
}
/** SUCCESSFUL, entity.getB() returns "b" as expected because Lombok.NotWorking has a {@link lombok.Builder.Default} annotation */
@Test
public void testD() {
Lombok.WithBuilderDefaultAnnotation entity = Lombok.WithBuilderDefaultAnnotation.builder().a("hello world").build();
assertEquals("b", entity.getB());
}
}
The text was updated successfully, but these errors were encountered:
Hey there
I have problems with the newly added @Builder.Default in v1.16.18.
It changes the behaviour of manual created constructors. It will leed to ignore default values of attributes (like
private String b = "b";
) if annotated with@Builder.Default
. I reduced this issue to the following two classes and test case which shows my expectations.classes:
unit tests:
The text was updated successfully, but these errors were encountered: