Skip to content

Migrate away from JSR305 - #5176

Merged
joschi merged 3 commits into
dropwizard:release/3.0.xfrom
zUniQueX:nullness-annotations
Apr 17, 2022
Merged

joschi merged 3 commits into
dropwizard:release/3.0.xfrom
zUniQueX:nullness-annotations

Conversation

@zUniQueX

Copy link
Copy Markdown
Member

As denoted in #5136, JSR305 causes problems on Java 9+ due to reusing the javax.annotation package.

But the annotations from JSR305 can be replaced with annotations from other packages. NullAway states in the configuration docs, that any annotations with the names @Nullable, @Nonnull, @NonNull and @NotNull are considered and not only those from JSR305. Therefore the annotations from org.jetbrains.annotations should be fine. (I've used Jetbrains' annotations here, since the package is much smaller than checker-qual or similar packages.)

The annotations of the package javax.annotation.concurrent can be replaced by annotations from errorprone. The errorprone docs additionally state, that the JSR305 @Immutable annotation is not evaluated, but the errorprone one is. So we should have an additional advantage there.

The one @NotThreadSafe annotation is replaced with jUnit's @Execution(SAME_THREAD), as it was done in #5149.

@zUniQueX
zUniQueX requested a review from a team as a code owner April 15, 2022 14:29
@jplock jplock added this to the 3.0.0 milestone Apr 15, 2022
@joschi

joschi commented Apr 15, 2022 •

Copy link
Copy Markdown
Member

(I've used Jetbrains' annotations here, since the package is much smaller than checker-qual or similar packages.)

The Checker framework is being pulled in by Caffeine and by Google Guava, so it's a dependency in almost all of our modules anyway.

Would it make sense to use the annotations from the Checker framework instead of replacing jsr305 with the JetBrains annotations? That way we at least would get rid of another dependency. 😉

@zUniQueX

Copy link
Copy Markdown
Member Author

Would it make sense to use the annotations from the Checker framework instead of replacing jsr305 with the JetBrains annotations? That way we at least would get rid of another dependency. 😉

I thought about this too. If we have a transitive dependency on that through guava and caffeine anyway, I don't see a big problem using those annotations. I just wanted to avoid pulling in a heavyweight dependency like checker-qual, if we just use a few annotations from it. Unfortunately, the Checker framework seems to have no extra package for the annotations.

I'll update this PR with replacing the Jetbrains annotations with the ones from the Checker framework in a separate commit, then we can revert it, if we change our mind.

@zUniQueX

zUniQueX commented Apr 15, 2022 •

Copy link
Copy Markdown
Member Author

@joschi I've now used checker-qual annotations and we can actually get rid of a few dependency declarations in addition to not introducing the org.jetbrains.annotations dependency 😉

However, the use of the annotations isn't as straightforward as using other nullness annotations, since the @Target meta annotation is different for the checker-qual ones.

@joschi joschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

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