0

We're trying to add "Nullaway" (https://github.com/uber/NullAway) to our repo. This is a tool that assumes everything not annotated with @Nullable can't be null and enforces it in compile time.

We also use Lombok, with focus on @Data. Lombok decides which fields to add to the RequiredArgsConstructor based on a @NonNull annotation. Furthermore, Nullaway requires that all constructurs set a value to all the fields not marked as @Nullable.

Our issue is - we don't wish to annotate all fields (both with @Nonnull and @Nullable), as it's redundant. We'd like to have one of them be a "default" (preferably the @Nonnull option).

How can we solve this? An ideal solution would be to configure the RequiredArgsConstructor to treat any field not marked as @Nullable as required, but that option doesn't exist. We're open to any and all creative ideas.

I tried looking for such a configuration in Lombok, which doesn't exist. I also tried annotating at the class level to no avail.

  • From the docs: "@RequiredArgsConstructor generates a constructor with 1 parameter for each field that requires special handling. All non-initialized final fields get a parameter, as well as any fields that are marked as @NonNull that aren't initialized where they are declared." Essentially what I'd like to do is change what it means to "require special handling". https://projectlombok.org/features/constructor – user1700773 Aug 31 '23 at 23:25
  • Did you read [this section](https://github.com/uber/NullAway#lombok) of the NullAway readme? – Sweeper Sep 01 '23 at 01:17

1 Answers1

0

Make a text file and name it lombok.config. Inside, stick some lines of text. See the documentation of the feature. You can tell lombok about your nullable annotations. You can also tell it to add @Generated annotations which NullAway understands - thanks to @Sweeper who linked to that section of the NullAway docs in the comments.

lombok.config can be in a package, or any parent directory of it; even / / C:\ though that'd perhaps be a bit weird. Generally you'd put this either in projectroot or projectroot/src.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72