You can achieve the same outcome not by @Builder.Default but by defining the builder itself with defaults for Lombok:

@Builder
public record FileProperties (
        String directory,
        String name,
        String extension
) {
    public static class FilePropertiesBuilder {
        FilePropertiesBuilder() {
            directory = System.getProperty("user.home");
            name = "New file";
            extension = ".txt";
        }
    }
}

Then to test it:

public static void main(String[] args) {
    System.out.println(FileProperties.builder().build());
}

Output:

FileProperties[directory=/home/me, name=New file, extension=.txt]
Answer from user21063779 on Stack Overflow
🌐
Project Lombok
projectlombok.org › features › Builder
@Builder
The initializer on a @Builder.Default field is removed and stored in a static method, in order to guarantee that this initializer won't be executed at all if a value is specified in the build. This does mean the initializer cannot refer to this, super or any non-static member.
🌐
Baeldung
baeldung.com › home › java › lombok builder with default value
Lombok Builder with Default Value | Baeldung
May 11, 2024 - The default values will be present with the builder, making the first test case pass. However, if we work with Lombok prior to version 1.18.2, the no-args constructor won’t get the default values, making the second test case fail.
🌐
Javadoc.io
javadoc.io › doc › org.projectlombok › lombok › 1.18.28 › lombok › Builder.Default.html
Builder.Default - lombok 1.18.28 javadoc
Latest version of org.projectlombok:lombok · https://javadoc.io/doc/org.projectlombok/lombok · Current version 1.18.28 · https://javadoc.io/doc/org.projectlombok/lombok/1.18.28 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org.projectlombok/lombok/1.18.28/package-list ·
🌐
Google Groups
groups.google.com › g › project-lombok › c › e9PzKXRlXXA
@Builder.Default and manual constructors
Having @Builder.Default on a field moves its initializer to a separate method, which is later called only of necessary by the builder's build() method. Lately, lombok significantly improved by also using this initializer method for generated @*ArgsConstructors.
🌐
Project Lombok
projectlombok.org › api › lombok › Builder.Default
Builder.Default (Lombok)
The field annotated with @Default must have an initializing expression; that expression is taken as the default to be used if not explicitly set during building.
🌐
Medium
bappy0.medium.com › why-lombok-builder-ignores-your-default-field-values-and-how-to-fix-it-5f0123bfd73b
Why Lombok’s @Builder Ignores Your Default Field Values (And How to Fix It) | by Rakib Hasan Bappy | Medium
September 23, 2025 - Without @Builder.Default, fields default to Java’s default values ( null, 0, f, etc.) when not set in the builder. ... Your entity or DTO class uses Lombok @Builder.
Find elsewhere
🌐
GitHub
github.com › projectlombok › lombok › issues › 3547
[BUG] @lombok.Builder.Default does not work on records · Issue #3547 · projectlombok/lombok
November 14, 2023 - Applying @Defaultto a record class fails to compile. @lombok.Builder record Foo ( // Fails to compile. @lombok.Builder.Default String bar = "ok" ) {} The expected behaviour is that works as in a normal class Lombok version: 1.18.30 Platf...
Author   projectlombok
🌐
Medium
medium.com › digitalfrontiers › project-lombok-fun-with-builders-389362ac2c01
Project Lombok: Fun with Builders! | by Benedikt Jerat | Digital Frontiers — Das Blog | Medium
October 28, 2022 - For this use case, it’s enough to just define the default builder class and add whatever functionality is needed. The rest of the builder class will be generated by Lombok behind the scenes.
Top answer
1 of 9
90

My guess is that it's not possible (without having delomboked the code). But why don't you just implement the constructor you need? Lombok is meant to make your life easier, and if something won't work with Lombok, just do it the old fashioned way.

@Data
@Builder
@AllArgsConstructor
public class UserInfo { 
    private int id;
    private String nick;
    @Builder.Default
    private boolean isEmailConfirmed = true;
    
    public UserInfo(){
        isEmailConfirmed = true;
    }
}

Console output:

ui: true
ui2: true

Update
As of 01/2021, this bug seems to be fixed in Lombok, at least for generated constructors. Note that there is still a similar issue when you mix Builder.Default and explicit constructors.

2 of 9
57

Since the @Builder.Default annotation is broken, I wouldn't use it at all. You can, however, use the following approach by moving the @Builder annotation from class level to the custom constructor:

@Data
@NoArgsConstructor
public class UserInfo {
    
    private int id;
    private String nick;
    private boolean isEmailConfirmed = true;

    @Builder
    @SuppressWarnings("unused")
    private UserInfo(int id, String nick, Boolean isEmailConfirmed) {
        this.id = id;
        this.nick = nick;
        this.isEmailConfirmed = Optional.ofNullable(isEmailConfirmed).orElse(this.isEmailConfirmed);
    }
}

This way you ensure:

  • the field isEmailConfirmed is initialized only in one place making the code less error-prone and easier to maintain later
  • the UserInfo class will be initialized the same way either you use a builder or a no-args constructor

In other words, the condition holds true:

new UserInfo().equals(UserInfo.builder().build())

In that case, the object creation is consistent no matter how you create it. It is especially important when your class is used by a mapping framework or by JPA provider when you are not instantiating it manually by a builder but a no-args constructor is invoked behind your back to create the instance.

The approach described above is very similar but it has a major drawback. You have to initialize the field in two places which makes the code error-prone as you are required to keep the values consistent.

🌐
Coderanch
coderanch.com › t › 779610 › frameworks › Builder-Default-working-expected
@Builder.Default not working as expected (Spring forum at Coderanch)
February 12, 2024 - Example data for the above is { "legalEntitySetting":null, "globalSetting":"ABC", "memoSetting":"TEST memo" } When I fetch the data (settingsRepository.findById()), I am getting it as follows { "legalEntitySetting":null, "globalSetting":"ABC", "memoSetting":"TEST memo", "isReconciled": "false" } Why isn't the Builder.Default not working and initializing the isReconciled flag to true? Thanks in Advance. ... Can you try some later versions of Lombok, such as version 1.18.2?
🌐
Reinhard
blog.reinhard.codes › 2016 › 07 › 13 › using-lomboks-builder-annotation-with-default-values
Using Lombok's @Builder annotation with default values | reinhard.codes
July 13, 2016 - Update: Lombok v1.16.16 adds a new feature that makes default builder values a bit easier to work with: @Builder.Default.
🌐
Project Lombok
projectlombok.org › features › Value
@Value
If true, lombok will generate a private no-args constructor for any @Value annotated class, which sets all fields to default values (null / 0 / false).
🌐
HowToDoInJava
howtodoinjava.com › home › lombok › lombok @builder
Lombok @Builder with Examples- HowToDoInJava
December 15, 2021 - In such cases, we can use the @Builder.Default on those fields.
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8254009
[JDK-8254009] Support for builder defaults in records
October 1, 2020 - See: https://projectlombok.org... the '@Builder.Default' annotation is running into a problem: There is no way to specify default values for a record's fields that works in the context of a lombok Builder....
🌐
Project Lombok
projectlombok.org › features › experimental › SuperBuilder
@SuperBuilder
This is the name of the generated builder class; any star in the name is replaced with the relevant return type. Note that the parent class must also have the same setting (the entire type hierarchy annoated with @SuperBuilder needs the same setting). lombok.superBuilder.flagUsage = [warning | error] (default: not set)
🌐
GitHub
github.com › projectlombok › lombok › issues › 2342
[FEATURE] need for @Builder.Default ? · Issue #2342 · projectlombok/lombok
January 19, 2020 - Describe the feature I must use @Builder.Default when using @Builder on class level: // must add this annotation to tell lombok @Builder.Default // it already has a "new" keyword which can also tell lombok to create its instance private ...
Author   projectlombok
🌐
Hacker News
news.ycombinator.com › item
The @Builder annotation has some odd behavior if you want to add default values ... | Hacker News
February 1, 2019 - Actually, anything involving default values seems to be very brittle and difficult to work with -- especially when deserializing objects from JSON · The @Wither annotation results in methods that do not always make a copy, and sometimes use == instead of .equals when comparing class members.