Migrate to Java 21

MSAL

This 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.UpgradeToJava21
mod run . --recipe=org.openrewrite.java.migrate.UpgradeToJava21

Install 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.

  1. Migrate to Java 17
  2. Upgrade build to Java 21
  3. Remove extra semicolons
  4. Replace Thread.resume(), Thread.stop(), and Thread.suspend() with throw new UnsupportedOperationException()
  5. Convert new URL(String) to URI.create(String).toURL()
  6. Adopt SequencedCollection
  7. Prefer Locale.of(..) over new Locale(..)
  8. Replace deprecated Runtime#exec() methods
  9. Upgrade actions/setup-java java-version
  10. Upgrade plugins to Java 21 compatible versions
  11. Avoid using the deprecated empty finalize() method in java.desktop
  12. Adopt javax.security.auth.Subject.current() and javax.security.auth.Subject.callAs() methods
  13. Replace if-else-if-else with switch
  14. Add null check to existing switch cases
  15. Convert assigning switch statements to switch expressions
  16. Convert switch cases where every case returns into a returned switch expression
  17. Convert switch expression yield to arrow
  18. Adopt switch pattern matching (JEP 441)