Skip to content
New issue

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

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

Already on GitHub? # to your account

Field in unannotated code should be considered non-null only for field reads #1101

Closed
agrieve opened this issue Dec 19, 2024 · 6 comments · Fixed by #1102
Closed

Field in unannotated code should be considered non-null only for field reads #1101

agrieve opened this issue Dec 19, 2024 · 6 comments · Fixed by #1102

Comments

@agrieve
Copy link

agrieve commented Dec 19, 2024

(Sorry if this is filed somewhere already)

It's come up a couple times now where we have generated code that creates struct-like classes with public fields. The NullAway default for unannotated code is to treat public fields as non-null, which removes warnings for field reads, but not for field writes. It would be great if fields of of unannotated classes would be considered @Nullable in the context of field writes.

In the particular case I'm working, I can update our code generator to annotate the fields, but thought I'd file this anyways.

@msridhar
Copy link
Collaborator

This is not expected. How is the code designated as unannotated? Is it generated into a different package?

@agrieve
Copy link
Author

agrieve commented Dec 19, 2024

I'm setting -XepOpt:NullAway:AnnotatedPackages= such that no classes are considered annotated unless they are marked with @NullMarked.

@msridhar
Copy link
Collaborator

Thanks for the report; a PR fix is up now. This bug has existed in NullAway for years!

@msridhar
Copy link
Collaborator

@agrieve would it be helpful to you to have a release with this fix?

@agrieve
Copy link
Author

agrieve commented Dec 19, 2024

Thanks for such a quick fix! I've fixed our main code generator that emitted these fields, so I don't think there'd be many other instances, so I wouldn't cut a release just for this if there's some overhead in doing so.

@msridhar
Copy link
Collaborator

Ok, sounds good. I might wait then until we can get a couple more fixes in.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants