Repository navigation
Conversation
…n migration JavaxAnnotationMigrationToJakartaAnnotation renamed the whole javax.annotation package, which also moved JSR-305 annotations such as CheckReturnValue and CheckForNull to jakarta.annotation, where they don't exist. Rename the jakarta.annotation-api types by name instead, and only rename the package for references the parser could not resolve, in files without a resolved javax.annotation type.
timtebeek
reviewed
Oct 21, 2026
Comment on lines
+193
to
+207
| name: org.openrewrite.java.migrate.jakarta.ChangeUnresolvedJavaxAnnotationPackage | ||
| displayName: Migrate unresolved `javax.annotation` types to `jakarta.annotation` | ||
| description: >- | ||
| Rename `javax.annotation` references whose types could not be resolved, such as annotations that came from the JDK | ||
| in Java 8 models. Files that still use a resolved `javax.annotation` type keep their package, as those are JSR-305 | ||
| annotations without a Jakarta equivalent. | ||
| preconditions: | ||
| - org.openrewrite.java.search.DoesNotUseType: | ||
| fullyQualifiedTypeName: javax.annotation.* | ||
| recipeList: | ||
| - org.openrewrite.java.ChangePackage: | ||
| oldPackageName: javax.annotation | ||
| newPackageName: jakarta.annotation | ||
| # Avoid changing javax.annotation.concurrent and javax.annotation.processing | ||
| recursive: false |
Member
There was a problem hiding this comment.
Maybe I'm misunderstanding, but I don't see this do very much with the precondition making it such that the ChangePackage can't match the same. What's the thinking or use case here?
javax.annotation in the Jakarta annotation migrationjavax.annotation in the Jakarta annotation migration
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.
What's changed?
JavaxAnnotationMigrationToJakartaAnnotationrenamed the wholejavax.annotationpackage. That package is shared with JSR-305 (CheckReturnValue,CheckForNull,ParametersAreNonnullByDefault,Nonnegative, ...), whose annotations don't exist injakarta.annotation, so migrated code stopped compiling.Before
After (main): compilation failure
After (this PR)
The recipe now:
jakarta.annotation-apitypes by name withChangeType(Generated,ManagedBean,PostConstruct,PreDestroy,Priority,Resource,Resources, andNonnull/Nullableas before);ChangeUnresolvedJavaxAnnotationPackage, guarded byDoesNotUseType javax.annotation.*.ChangeTypeonly matches resolved types, so this keeps migrating Java 8 models where these annotations came from the JDK (addApiForUnattributedJdkAnnotation), without touching files that still use a resolved JSR-305 annotation.Tests
keepsJsr305Annotations,migratesJsr250AnnotationsNextToJsr305,splitsWildcardImportBetweenJakartaAndJsr305(import javax.annotation.*used for both),migratesEveryJakartaAnnotationApiType.ProvidedJakartaApiScopeTestnow uses an import instead of a fully qualified field, sinceChangeTypeshortens fully qualified references.Known limitations
javax, because the guard is per file.ChangeTypecan add an import that shadows a same-package class with the same simple name (@javax.annotation.Resourcenext to a classResourcein the same package). This is aChangeTypeissue in rewrite core; a fix is in progress there.Related
ChangePackage; comments report the JSR-305 breakage, Knut suggested an exceptions optionAddCommonAnnotationsDependencies