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

Test for missing @NotNull / @Nullable annotations #361

Open
ljacqu opened this issue Aug 24, 2023 · 1 comment
Open

Test for missing @NotNull / @Nullable annotations #361

ljacqu opened this issue Aug 24, 2023 · 1 comment
Milestone

Comments

@ljacqu
Copy link
Member

ljacqu commented Aug 24, 2023

Write a unit test that scans the parameters of methods and constructors, and the return value of methods and that reports any that don't have @NotNull or @Nullable.

To do

  • Add org.reflections as a test dependency
  • Write a test that collects all classes of ConfigMe
    • Skip classes that end in "Test"
  • Collect all method/constructor params and method return values
  • Report all instances where neither nullability annotation is used
    • Special case arrays: T @NotNull [] is how the array itself is reported not null. Probably should also check the component if possible?
    • Begs the question what to do with other generic types such as List<String> (vs. List<@NotNull String>)...?
@ljacqu
Copy link
Member Author

ljacqu commented Aug 30, 2023

Seems impossible to do currently:

  • @NotNull and @Nullable have SOURCE retention, so need to use org.reflections or javassist to pick out the values
  • org.reflections has no way of returning whether a specific method parameter has an annotation
  • javassist has a bug where it thinks @Foo String[] means the array is annotated, while it's supposed to be String @Foo []. This leads to a lot of false positives.

@ljacqu ljacqu added this to the Backlog milestone Aug 30, 2023
ljacqu added a commit that referenced this issue Aug 31, 2023
- One problem is that javassist does not recognize `String @nullable []` as the annotation being for the whole type, leading to a lot of false positives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant