Add RemoveDuplicateAnnotations - #1000
Merged
Merged
Conversation
When several distinct annotations are migrated to a single new annotation -- for instance `javax.annotation.Nullable` and `javax.annotation.CheckForNull` both becoming `org.jspecify.annotations.Nullable` -- each `ChangeType` rewrites its own annotation, leaving the element annotated twice. Remove annotations repeated on the same element, keeping the first occurrence. Only annotations semantically equal to an earlier one are removed, and `@Repeatable` annotations are left alone.
timtebeek
added a commit
to openrewrite/rewrite-migrate-java
that referenced
this pull request
Aug 13, 2026
The recipe is not specific to JSpecify: any many-to-one `ChangeType` mapping can leave an element annotated twice. It now lives in rewrite-static-analysis, next to `RemoveDuplicateConditions`, with an optional `annotationType` defaulting to any annotation and a guard for `@Repeatable` annotations. See openrewrite/rewrite-static-analysis#1000
Member
Author
|
CI is red on ten TypeScript tests ( |
A published rewrite-javascript snapshot pins an exact @openrewrite/rewrite version, and the npm release of that version can lag the Maven one. The RPC process then has nothing to run and every typescript() test fails. warmJavaScriptRpcCache already writes its marker only for an install that succeeded, so publish that as javaScriptRpcAvailable and let the tests that need the RPC server skip rather than fail the build over a gap upstream. This also covers a machine without Node, which the warm task already declines to require.
timtebeek
added a commit
to openrewrite/rewrite-migrate-java
that referenced
this pull request
Aug 14, 2026
… one (#1200) * Do not duplicate JSpecify annotations when several annotations map to one When an element carries two nullability annotations that both migrate to the same JSpecify annotation -- such as `javax.annotation.Nullable` together with `javax.annotation.CheckForNull`, or annotations from two different frameworks -- the `ChangeType` steps each rewrite their own annotation, leaving the element annotated twice. Add a `RemoveDuplicateAnnotations` recipe that drops repeated annotations of the same type, and run it at the end of each `MigrateFrom*` recipe. Fixes #1199 * Use ListUtils.filter to drop duplicate annotations * Move `RemoveDuplicateAnnotations` to rewrite-static-analysis The recipe is not specific to JSpecify: any many-to-one `ChangeType` mapping can leave an element annotated twice. It now lives in rewrite-static-analysis, next to `RemoveDuplicateConditions`, with an optional `annotationType` defaulting to any annotation and a guard for `@Repeatable` annotations. See openrewrite/rewrite-static-analysis#1000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When several distinct annotations migrate to a single new annotation, each
ChangeTyperewrites its own annotation and the element ends up annotated twice:@Nullable @Nullable String baz— sometimes with one of the two fully qualified, when the simple name can no longer be shortened. That is a compile error for non-@Repeatableannotations. See JSpecifyBestPractices add @Nullable annotionen to params twice rewrite-migrate-java#1199 for a report in the wild.This recipe removes annotations repeated on the same element, keeping the first occurrence. It covers leading annotations on classes, methods and variables, annotations attached to modifiers, and type-use annotations on array types, nested types and type arguments.
Two guards keep it conservative:
@Nullable @NonNulland@Tag("a") @Tag("b")are untouched;@Repeatableannotations are skipped, since repeating those is meaningful.annotationTypeis optional and defaults to any annotation, so the recipe is useful standalone; rewrite-migrate-java will call it withorg.jspecify.annotations.*from its JSpecify migrations.