Skip to content

NonNull fields with user-written defaults in Lombok builders #58

@kelloggm

Description

@kelloggm

Similar to #52, sometimes programmers write @NonNull on Optional types. Unlike AutoValue, Lombok has no built-in support for this, so there's no equivalent thing to do for Lombok.

However, we still get false positives like this:

@lombok.Builder
public class Foo {
   @lombok.NonNull Optional<String> bar;

      public static class FooBuilder {
          private Optional<String> foo = Optional.empty();
     }
}

That is, the builder defaults the optional to being empty, and Lombok generates the rest - making the @NonNull annotation redundant.

This problem, however, is more general: a programmer could set a default in this manner even for non-optional fields, and we would issue a false positive expecting that field to be set.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions