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

Ignore incompatibly annotated var args from Kotlin code. #721

Merged
merged 2 commits into from
Jan 26, 2023

Conversation

lazaroclapp
Copy link
Collaborator

See #720 for a detailed explanation.

Long story short:

  1. kotlinc will add @org.jetbrains.annotations.NotNull as a declaration annotation for any argument that is non-null, which we pick up from jars when running with AcknowledgeRestrictiveAnnotations=true.
  2. Unfortunately, it will mark code such as open fun w(vararg args: Any?) as having @NotNull args (meaning the array itself).
  3. This is indistinguishable at the bytecode level from Java code such as w(@NotNull Object... args), which we believe should be interpreted as marking the elements of args as being @NotNull.
  4. This PR hacks RestrictiveAnnotationHandler to skip @org.jetbrains.annotations.NotNull on var args only.

Additionally, our basic handling of var args is pretty broken. I went over our test cases and commented where I think our current behavior is different from the desired behavior as documented in #720 and #674. Foregoing fixing it for now, as I am worried about the breaking change and I think we want to avoid changing that before 0.10.9.

@coveralls
Copy link

Pull Request Test Coverage Report for Build #1041

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.009%) to 93.024%

Totals Coverage Status
Change from base Build #1040: 0.009%
Covered Lines: 5281
Relevant Lines: 5677

💛 - Coveralls

" Utilities.takesNullableVarargs(o1, o4);",
" Utilities.takesNullableVarargs(o1, (java.lang.Object) null);",
// SHOULD be an error!
" Utilities.takesNullableVarargs(o1, (java.lang.Object[]) null);",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Turns out there is a way to pass null varargs array from Java 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, interesting. Didn't think of this one

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.

Change LGTM and I agree it's the best we can do for the moment to address this issue

" Utilities.takesNullableVarargs(o1, o4);",
" Utilities.takesNullableVarargs(o1, (java.lang.Object) null);",
// SHOULD be an error!
" Utilities.takesNullableVarargs(o1, (java.lang.Object[]) null);",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, interesting. Didn't think of this one

@lazaroclapp lazaroclapp merged commit 0a78a82 into master Jan 26, 2023
@msridhar msridhar deleted the lazaro_nullable_varargs_of_unannotated_code 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
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.

None yet

3 participants