Migrate to Java 21
MSALThis recipe will apply changes commonly needed when migrating to Java 21. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 21 as the target/source and plugins will also be upgraded to versions that are compatible with Java 21.
org. openrewrite. java. migrate. UpgradeToJava21mod run . --recipe= org. openrewrite. java. migrate. UpgradeToJava21Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Migrate to Java 17
- Upgrade build to Java 21
- Remove extra semicolons
- Replace
Thread.resume(),Thread.stop(), andThread.suspend()withthrow new UnsupportedOperationException() - Convert
new URL(String)toURI.create(String).toURL() - Adopt
SequencedCollection - Prefer
Locale.of(..)overnew Locale(..) - Replace deprecated
Runtime#exec()methods - Upgrade
actions/setup-javajava-version - Upgrade plugins to Java 21 compatible versions
- Avoid using the deprecated empty
finalize()method injava.desktop - Adopt
javax.security.auth.Subject.current()andjavax.security.auth.Subject.callAs()methods - Replace if-else-if-else with switch
- Add null check to existing switch cases
- Convert assigning switch statements to switch expressions
- Convert switch cases where every case returns into a returned switch expression
- Convert switch expression yield to arrow
- Adopt switch pattern matching (JEP 441)