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 an initial annotations artifact (with sample @Initializer implementation) #709

Merged
merged 4 commits into from
Jan 5, 2023

Conversation

lazaroclapp
Copy link
Collaborator

@lazaroclapp lazaroclapp commented Jan 4, 2023

The main purpose of this change is to introduce our own annotations artifact, which
can be leveraged to implement more general contracts and other annotations of
interest to NullAway.

Additionally, we start by having our own @Initializer annotation "implementation"
in this annotations jar. I believe Facebook/Meta's Eradicate is being sunset in favor of
Nullsafe (internally at Meta) and NullAway (for OSS), and either way recommending
their annotation jar for NullAway is more of a historical artifact of nullness checking at
Uber and our previous use of Infer/Eradicate than anything else. NullAway will still
acknowledge any annotation with simple name @Initializer, but now we can
recommend a canonical alternative which we can make sure remains supported.

Additionally, we take the opportunity to make our @Initializer valid only on method
declarations (which is the only place NullAway checks for it).

We use annotations rather than annotation, because that's the choice JSpecify
0.3.0 went with in the end, and I refuse to spend another year discussing that 😉

@lazaroclapp
Copy link
Collaborator Author

As a follow up diff, we could consider having our own implementations of @EnsuresNonNull and @RequiresNonNull, and even Jetbrain's @Contract. But I actually think all those cases can be subsumed by a new @NullAwayContract which can be included in this new jar, while we still support the existing CF/Jetbrains annotations with their upstream intended semantics.

@coveralls
Copy link

coveralls commented Jan 4, 2023

Pull Request Test Coverage Report for Build #1031

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.995%

Totals Coverage Status
Change from base Build #1029: 0.0%
Covered Lines: 5191
Relevant Lines: 5582

💛 - Coveralls

* framework events such as {@code onCreate}).
*/
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.METHOD})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One thing to note: this prevents @Initializer in constructors, which was valid before and could be used to mean "ignore all other constructors, if this one initializes it, then we are good!". Not sure how useful that was as a feature, though, and it wasn't exactly intended...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you saying NullAway actually supports this interpretation of @Initializer on constructors? If so maybe we should remove that at some point? In any case I agree we don't want it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does, unless something changed and we haven't checked: #540. It's not high priority to fix, but no reason why we should perpetuate it on our own annotation :)

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.

Mostly LGTM, just a couple minor things

#

POM_NAME=NullAway
POM_ARTIFACT_ID=annotations
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean the Gradle identifier for the artifact will be :com.uber.nullaway:annotations:X.Y.Z? If so I think I prefer nullaway-annotations as the artifact ID.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good to me! Do we want to also change the dir name within our repo? Or are we fine with annotations/ (I think the later, but would be fine either way)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the directory name is fine

* framework events such as {@code onCreate}).
*/
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.METHOD})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you saying NullAway actually supports this interpretation of @Initializer on constructors? If so maybe we should remove that at some point? In any case I agree we don't want it.

@@ -48,7 +49,6 @@ dependencies {
testImplementation deps.test.cfCompatQual
testImplementation deps.build.jspecify
testImplementation project(":test-java-lib")
testImplementation deps.test.inferAnnotations
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we just remove inferAnnotations entirely from dependencies.gradle? Or is it still used somewhere?

@lazaroclapp lazaroclapp enabled auto-merge (squash) January 5, 2023 20:32
@lazaroclapp lazaroclapp merged commit afb8fd4 into master Jan 5, 2023
@msridhar msridhar deleted the lazaro_nullaway_lib_initial branch March 9, 2023 17:06
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
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.

None yet

3 participants