Add @Nullable annotations for pegasus java getters and setters with mode #932
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
This PR adds
@Nullable
annotation to the Java data template generator that generates getters and setters for pegasus data models. Specifically:@Nullable
annotations. E.g.Foo.setBar(blah, SetMode mode)
=>Foo.setBar(@Nullable blah, SetMode mode)
sinceFoo.setBar(blah, SetMode.REMOVE_IF_NULL)
is null-safe.@Nullable
annotation. E.g.Foo.getBar(GetMode mode)
=>@Nullable Foo.getBar(GetMode mode)
sinceFoo.getBar(GetMode.IGNORE_NULL)
is null-safe.Context
PSM recently introduced NullAway (https://github.com/uber/NullAway) as a requirement for LMS MPs. However, the library caught several false positives on Rest.Li generated java code, specifically on the cases mentioned above due to missing annotations. Adding these annotations should reduce the false positives from the library.
Testing Done
Build in Java 8:
Generated local release and tested in Java 11 consumer (following workaround in SI-31264 and SI-30640
./scripts/local-release -s
Example Getter with Mode (required field):
Example Setter with Mode (required field)