Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for external init annotations in constructors #725

Merged
merged 1 commit into from
Jan 31, 2023

Conversation

lazaroclapp
Copy link
Collaborator

NullAway has existing support for -XepOpt:NullAway:ExternalInitAnnotations=... as configuration option.
Before this PR, that option allows listing a set of class-level annotations with the following semantics:

A list of annotations for classes that are "externally initialized." Tools like the Cassandra Object Mapper do their own field initialization of objects with a certain annotation (like @Table), after invoking the zero-argument constructor. For any class annotated with an external-init annotation, we don't check that the zero-arg constructor initializes all non-null fields.

This PR extends that configuration option to also allow annotations that are added directly to the zero-arguments
constructor of such an externally initialized class. The reason for this is that it's often desired to document why
the empty constructor exists, and doing so at the declaration site for the constructor makes code more readable than
doing so at the class declaration level.

The canonical example here is GSON serialization, which requires classes to have a private zero-arguments constructor
which is called for deserialization, in addition to their normal initializing constructors.

As a follow up to this PR landing, we will update the Wiki docs accordingly.

@coveralls
Copy link

Pull Request Test Coverage Report for Build #1045

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 11 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.002%) to 93.02%

Files with Coverage Reduction New Missed Lines %
../nullaway/src/main/java/com/uber/nullaway/NullAway.java 11 96.12%
Totals Coverage Status
Change from base Build #1044: 0.002%
Covered Lines: 5277
Relevant Lines: 5673

💛 - Coveralls

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lazaroclapp lazaroclapp merged commit d2e4a49 into master Jan 31, 2023
@lazaroclapp
Copy link
Collaborator Author

@lazaroclapp lazaroclapp deleted the lazaro_external_init_annot_constructors branch January 31, 2023 02:27
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 18, 2023
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 19, 2023
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 19, 2023
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants