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

Unexpected behaviour with newly added @Builder.Default #1444

Closed
5im5im opened this issue Jul 18, 2017 · 2 comments
Closed

Unexpected behaviour with newly added @Builder.Default #1444

5im5im opened this issue Jul 18, 2017 · 2 comments

Comments

@5im5im
Copy link

5im5im commented Jul 18, 2017

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:

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

See #1347 and #1429

@Rawi01
Copy link
Collaborator

Rawi01 commented Mar 12, 2024

Duplicate of #2340

@Rawi01 Rawi01 marked this as a duplicate of #2340 Mar 12, 2024
@Rawi01 Rawi01 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
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