Javadoc “cannot find symbol” error when using Lombok’s @Builder annotation

Lombok is actually capable of filling out a partially defined builder class, so you can declare enough of the builder to make Javadoc happy and leave it at that. No need to delombok.

The following worked for me in this situation:

@Data
@Builder
public class Foo {
    private String param;

    // Add this line and all is good
    public static class FooBuilder {}

}

Side note: that you can actually use this technique to add some customer builder methods, so it has perks. I like to overload builder methods when I have collections so I can items one at a time. There’s probably already some technique that does that, but it’s nice to know you can improve the builders manually.

Here’s a common thing I like to do:

@Builder
public class Foo {
    private final String command;
    private final List<String> params;
    private final boolean background;
    
    public static class FooBuilder {
        public FooBuilder params(final String... params) {
            this.params = Arrays.asList(params);
            return this;
        }
    }
}

In the above the params builder method has been customized to take var args. The other builder method will still be created by Lombok.

Leave a Comment