Skip to content

Add mapping for CheckForNull to JSpecify annotation - #1179

Merged
timtebeek merged 2 commits into
openrewrite:mainfrom
zbynek:patch-1
Jul 31, 2026
Merged

Add mapping for CheckForNull to JSpecify annotation#1179
timtebeek merged 2 commits into
openrewrite:mainfrom
zbynek:patch-1

Conversation

@zbynek

@zbynek zbynek commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What's changed?

When migrating to JSpecify. javax.annotation.CheckForNull is now replaced by org.jspecify.annotations.Nullable.
Semantically CheckForNull is closer to org.jspecify.annotations.Nullable than javax.annotation.Nullable is (see StackOverflow), so this is a safe change.

What's your motivation?

  • The recipe should remove all null-related annotations that belong to javax.annotation to avoid manual steps.
  • Currently the recipe changes @CheckForNull Object[] to Object @CheckForNull[], but then fails to replace it, resulting in code that does not compile (the old annotation does not have TYPE_USE target).

Anything in particular you'd like reviewers to focus on?

🤷

Anyone you would like to review specifically?

🤷

Have you considered any alternatives or workarounds?

Make a custom .yml recipe.

Any additional context

Projects using SpotBugs for null analysis likely prefer @CheckForNull over javax.annotation.Nullable, so they might benefit from this change.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jul 30, 2026
@zbynek
zbynek force-pushed the patch-1 branch 2 times, most recently from 3b4dc33 to fbcfe6c Compare July 30, 2026 21:34
@zbynek

zbynek commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author
./gradlew test --tests "*JSpecifyBestPracticesTest"

succeeds but

./gradlew test

fails locally -- most of the failed tests seem to be related to openrewrite/rewrite#8355 -- @timtebeek looped.

@zbynek
zbynek marked this pull request as ready for review July 30, 2026 21:52
@timtebeek
timtebeek self-requested a review July 30, 2026 22:14

@timtebeek timtebeek 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 a lot, also for the helpful link explaining the nuances. I've rebased and will merge when CI succeeds

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Jul 30, 2026
@timtebeek
timtebeek merged commit 563608f into openrewrite:main Jul 31, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants