lombok-intellij-plugin icon indicating copy to clipboard operation
lombok-intellij-plugin copied to clipboard

Plugin should warn about missing @NonNull fields when object is created by builder

Open drnow4u opened this issue 4 years ago • 1 comments

Short description

As a developer I want to lombok-intellij-plugin warns me about missing fields annotated with @NonNull we object is created with builder. Without it it is only possible to find missing fields during runtime.

Expected behavior

Consider code:

@Builder
class User{
    @NonNull
    private final String firstName;
    @NonNull
    private final String lastName;

    public static void main(String[] args) {
        User user = User.builder()
                .firstName("Marcin")
                .build(); // Plugin should warn about missing @NonNull fields when object is created by builder
    }
}

Plug-in is warning developer somewhere between line User user = User.builder() and .build(); about missing non null fields. When the field has default value plug-in should not warn.

Why is it useful

I think this features can help to find a bugs and save a lot of developer's time. Especially it is important for not tested or hard to test occasionally run part of code.

drnow4u avatar Apr 26 '20 21:04 drnow4u

This was mentioned as the preferred solution to https://github.com/projectlombok/lombok/wiki/FEATURE-IDEA:-%22Mandatory%22-fields-with-@Builder

XHawk87 avatar Feb 21 '24 21:02 XHawk87