From 0d67e589cd87dadc02a0e487f76cf4df29dda259 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 26 Jul 2026 23:14:50 +0200 Subject: [PATCH 1/3] Fix method patterns for `UnsignedInts`/`UnsignedLongs` recipes Guava's `UnsignedInts`/`UnsignedLongs` have no `remainderUnsigned`, `compareUnsigned` or `divideUnsigned` methods; the real names are `remainder`, `compare` and `divide`. Six of the eight method patterns in this block therefore never matched: - `PreferIntegerRemainderUnsigned` and `PreferLongRemainderUnsigned` targeted a nonexistent `remainderUnsigned`; they now rename `remainder` first, mirroring the existing Compare/Divide chaining. - `PreferLongCompareUnsigned` and `PreferLongDivideUnsigned` declared `(int, int)` where `UnsignedLongs` takes `(long, long)`. - `PreferLongParseUnsignedLong` pointed at `UnsignedInts` rather than `UnsignedLongs`, and its display name and description said `parseUnsignedInt`. Also add `PreferIntegerRemainderUnsigned` to `NoGuava`, as it was declared but never referenced, and add `NoGuavaUnsignedTest` to cover all four conversions per type. --- .../resources/META-INF/rewrite/no-guava.yml | 27 +++--- .../resources/META-INF/rewrite/recipes.csv | 10 +-- .../migrate/guava/NoGuavaUnsignedTest.java | 89 +++++++++++++++++++ 3 files changed, 111 insertions(+), 15 deletions(-) create mode 100644 src/test/java/org/openrewrite/java/migrate/guava/NoGuavaUnsignedTest.java diff --git a/src/main/resources/META-INF/rewrite/no-guava.yml b/src/main/resources/META-INF/rewrite/no-guava.yml index 5f8210f810..20e5e30db3 100644 --- a/src/main/resources/META-INF/rewrite/no-guava.yml +++ b/src/main/resources/META-INF/rewrite/no-guava.yml @@ -68,6 +68,7 @@ recipeList: - org.openrewrite.java.migrate.guava.PreferIntegerCompareUnsigned - org.openrewrite.java.migrate.guava.PreferIntegerDivideUnsigned - org.openrewrite.java.migrate.guava.PreferIntegerParseUnsignedInt + - org.openrewrite.java.migrate.guava.PreferIntegerRemainderUnsigned - org.openrewrite.java.migrate.guava.PreferJavaStringJoin - org.openrewrite.java.migrate.guava.PreferLongCompareUnsigned - org.openrewrite.java.migrate.guava.PreferLongDivideUnsigned @@ -414,12 +415,15 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferIntegerRemainderUnsigned displayName: Prefer `Integer#remainderUnsigned` -description: Prefer `java.lang.Integer#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedInts#remainderUnsigned`. +description: Prefer `java.lang.Integer#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedInts#remainder`. tags: - guava preconditions: - org.openrewrite.Singleton recipeList: + - org.openrewrite.java.ChangeMethodName: + methodPattern: com.google.common.primitives.UnsignedInts remainder(int, int) + newMethodName: remainderUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: methodPattern: com.google.common.primitives.UnsignedInts remainderUnsigned(int, int) fullyQualifiedTargetTypeName: java.lang.Integer @@ -437,10 +441,10 @@ preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodName: - methodPattern: com.google.common.primitives.UnsignedLongs compare(int, int) + methodPattern: com.google.common.primitives.UnsignedLongs compare(long, long) newMethodName: compareUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedLongs compareUnsigned(int, int) + methodPattern: com.google.common.primitives.UnsignedLongs compareUnsigned(long, long) fullyQualifiedTargetTypeName: java.lang.Long --- type: specs.openrewrite.org/v1beta/recipe @@ -455,38 +459,41 @@ preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodName: - methodPattern: com.google.common.primitives.UnsignedLongs divide(int, int) + methodPattern: com.google.common.primitives.UnsignedLongs divide(long, long) newMethodName: divideUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedLongs divideUnsigned(int, int) + methodPattern: com.google.common.primitives.UnsignedLongs divideUnsigned(long, long) fullyQualifiedTargetTypeName: java.lang.Long --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferLongParseUnsignedLong -displayName: Prefer `Long#parseUnsignedInt` -description: Prefer `java.lang.Long#parseUnsignedInt` instead of using `com.google.common.primitives.UnsignedLongs#parseUnsignedInt`. +displayName: Prefer `Long#parseUnsignedLong` +description: Prefer `java.lang.Long#parseUnsignedLong` instead of using `com.google.common.primitives.UnsignedLongs#parseUnsignedLong`. tags: - guava preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedInts parseUnsignedLong(String, ..) + methodPattern: com.google.common.primitives.UnsignedLongs parseUnsignedLong(String, ..) fullyQualifiedTargetTypeName: java.lang.Long --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferLongRemainderUnsigned displayName: Prefer `Long#remainderUnsigned` -description: Prefer `java.lang.Long#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#remainderUnsigned`. +description: Prefer `java.lang.Long#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#remainder`. tags: - guava preconditions: - org.openrewrite.Singleton recipeList: + - org.openrewrite.java.ChangeMethodName: + methodPattern: com.google.common.primitives.UnsignedLongs remainder(long, long) + newMethodName: remainderUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedLongs remainderUnsigned(int, int) + methodPattern: com.google.common.primitives.UnsignedLongs remainderUnsigned(long, long) fullyQualifiedTargetTypeName: java.lang.Long --- diff --git a/src/main/resources/META-INF/rewrite/recipes.csv b/src/main/resources/META-INF/rewrite/recipes.csv index 2532bf9114..89df13325c 100644 --- a/src/main/resources/META-INF/rewrite/recipes.csv +++ b/src/main/resources/META-INF/rewrite/recipes.csv @@ -49,7 +49,7 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.J maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JREThrowableFinalMethods,Rename final method declarations `getSuppressed()` and `addSuppressed(Throwable exception)` in classes that extend `Throwable`,The recipe renames `getSuppressed()` and `addSuppressed(Throwable exception)` methods in classes that extend `java.lang.Throwable` to `myGetSuppressed` and `myAddSuppressed(Throwable)`. These methods were added to Throwable in Java 7 and are marked final which cannot be overridden.,1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JREWrapperInterface,Add missing `isWrapperFor` and `unwrap` methods,Add method implementations stubs to classes that implement `java.sql.Wrapper`.,3,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.Java8toJava11,Migrate to Java 11,"This recipe will apply changes commonly needed when upgrading to Java 11. Specifically, for those applications that are built on Java 8, this recipe will update and add dependencies on J2EE libraries that are no longer directly bundled with the JDK. 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 11 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 11.",256,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JavaBestPractices,Java best practices,"Applies opinionated best practices for Java projects targeting Java 25. This recipe includes the full Java 25 upgrade chain plus additional improvements to code style, API usage, and third-party dependency reduction that go beyond what the version migration recipes apply.",1682,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JavaBestPractices,Java best practices,"Applies opinionated best practices for Java projects targeting Java 25. This recipe includes the full Java 25 upgrade chain plus additional improvements to code style, API usage, and third-party dependency reduction that go beyond what the version migration recipes apply.",1686,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JpaCacheProperties,Disable the persistence unit second-level cache,Sets an explicit value for the shared cache mode.,1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.Jre17AgentMainPreMainPublic,Set visibility of `premain` and `agentmain` methods to `public`,Check for a behavior change in Java agents.,5,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.Krb5LoginModuleClass,Use `com.sun.security.auth.module.Krb5LoginModule` instead of `com.ibm.security.auth.module.Krb5LoginModule`,Do not use the `com.ibm.security.auth.module.Krb5LoginModule` class.,2,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, @@ -128,7 +128,7 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.d maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.datanucleus.UpgradeDataNucleus_5_0,Migrate to DataNucleus 5.0,"Migrate DataNucleus 4.x applications to 5.0. This recipe handles package relocations, type renames, property key changes, and dependency updates.",55,,DataNucleus,Modernize,Java,,Recipes for migrating [DataNucleus](https://www.datanucleus.org/) JDO/JPA persistence applications.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.datanucleus.UpgradeDataNucleus_5_1,Migrate to DataNucleus 5.1,"Migrate DataNucleus applications to 5.1. This recipe first applies the 5.0 migration, then handles the transaction namespace reorganization and other property renames introduced in 5.1.",76,,DataNucleus,Modernize,Java,,Recipes for migrating [DataNucleus](https://www.datanucleus.org/) JDO/JPA persistence applications.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.datanucleus.UpgradeDataNucleus_5_2,Migrate to DataNucleus 5.2,"Migrate DataNucleus applications to 5.2. This recipe first applies the 5.1 migration, then handles the column mapping package move and query-related property renames introduced in 5.2.",87,,DataNucleus,Modernize,Java,,Recipes for migrating [DataNucleus](https://www.datanucleus.org/) JDO/JPA persistence applications.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.NoGuava,Prefer the Java standard library instead of Guava,"Guava filled in important gaps in the Java standard library and still does. But at least some of Guava's API surface area is covered by the Java standard library now, and some projects may be able to remove Guava altogether if they migrate to standard library for these functions.",185,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.NoGuava,Prefer the Java standard library instead of Guava,"Guava filled in important gaps in the Java standard library and still does. But at least some of Guava's API surface area is covered by the Java standard library now, and some projects may be able to remove Guava altogether if they migrate to standard library for these functions.",189,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.NoGuavaAtomicsNewReference,Prefer `new AtomicReference<>()`,Prefer the Java standard library over third-party usage of Guava in simple cases like this.,1,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.NoGuavaCollections2Transform,Prefer `Collection.stream().map(Function)` over `Collections2.transform`,"Prefer `Collection.stream().map(Function)` over `Collections2.transform(Collection, Function)`.",1,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.NoGuavaCreateTempDir,Prefer `Files#createTempDirectory()`,Replaces Guava `Files#createTempDir()` with Java `Files#createTempDirectory(..)`. Transformations are limited to scopes throwing or catching `java.io.IOException`.,1,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, @@ -173,7 +173,7 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.g maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerCompareUnsigned,Prefer `Integer#compareUnsigned`,Prefer `java.lang.Integer#compareUnsigned` instead of using `com.google.common.primitives.UnsignedInts#compare` or `com.google.common.primitives.UnsignedInts#compareUnsigned`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerDivideUnsigned,Prefer `Integer#divideUnsigned`,Prefer `java.lang.Integer#divideUnsigned` instead of using `com.google.common.primitives.UnsignedInts#divide` or `com.google.common.primitives.UnsignedInts#divideUnsigned`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerParseUnsignedInt,Prefer `Integer#parseUnsignedInt`,Prefer `java.lang.Integer#parseUnsignedInt` instead of using `com.google.common.primitives.UnsignedInts#parseUnsignedInt`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerRemainderUnsigned,Prefer `Integer#remainderUnsigned`,Prefer `java.lang.Integer#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedInts#remainderUnsigned`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerRemainderUnsigned,Prefer `Integer#remainderUnsigned`,Prefer `java.lang.Integer#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedInts#remainder`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferJavaNioCharsetStandardCharsets,Prefer `java.nio.charset.StandardCharsets`,Prefer `java.nio.charset.StandardCharsets` instead of using `com.google.common.base.Charsets`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferJavaStringJoin,Prefer `String#join()` over Guava `Joiner#join()`,Replaces supported calls to `com.google.common.base.Joiner#join()` with `java.lang.String#join()`.,1,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferJavaUtilCollectionsSynchronizedNavigableMap,Prefer `java.util.Collections#synchronizedNavigableMap`,Prefer `java.util.Collections#synchronizedNavigableMap` instead of using `com.google.common.collect.Maps#synchronizedNavigableMap`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, @@ -190,8 +190,8 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.g maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongCompare,Prefer `Long#compare`,Prefer `java.lang.Long#compare` instead of using `com.google.common.primitives.Longs#compare`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongCompareUnsigned,Prefer `Long#compareUnsigned`,Prefer `java.lang.Long#compareUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#compare` or `com.google.common.primitives.UnsignedLongs#compareUnsigned`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongDivideUnsigned,Prefer `Long#divideUnsigned`,Prefer `java.lang.Long#divideUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#divide` or `com.google.common.primitives.UnsignedLongs#divideUnsigned`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongParseUnsignedLong,Prefer `Long#parseUnsignedInt`,Prefer `java.lang.Long#parseUnsignedInt` instead of using `com.google.common.primitives.UnsignedLongs#parseUnsignedInt`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongRemainderUnsigned,Prefer `Long#remainderUnsigned`,Prefer `java.lang.Long#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#remainderUnsigned`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongParseUnsignedLong,Prefer `Long#parseUnsignedLong`,Prefer `java.lang.Long#parseUnsignedLong` instead of using `com.google.common.primitives.UnsignedLongs#parseUnsignedLong`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongRemainderUnsigned,Prefer `Long#remainderUnsigned`,Prefer `java.lang.Long#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#remainder`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathAddExact,Prefer `Math#addExact`,Prefer `java.lang.Math#addExact` instead of using `com.google.common.math.IntMath#checkedAdd` or `com.google.common.math.IntMath#addExact`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathClamp,Prefer `Math#clamp`,Prefer `java.lang.Math#clamp` instead of using `com.google.common.primitives.*#constrainToRange`.,7,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathMultiplyExact,Prefer `Math#multiplyExact`,Prefer `java.lang.Math#multiplyExact` instead of using `com.google.common.primitives.IntMath#checkedMultiply` or `com.google.common.primitives.IntMath#multiplyExact`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, diff --git a/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaUnsignedTest.java b/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaUnsignedTest.java new file mode 100644 index 0000000000..725c18bda6 --- /dev/null +++ b/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaUnsignedTest.java @@ -0,0 +1,89 @@ +/* + * Copyright 2026 the original author or authors. + *

+ * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.migrate.guava; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.InMemoryExecutionContext; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; + +class NoGuavaUnsignedTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec + .recipeFromResources("org.openrewrite.java.migrate.guava.NoGuava") + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "guava")); + } + + @DocumentExample + @Test + void unsignedInts() { + //language=java + rewriteRun( + java( + """ + import com.google.common.primitives.UnsignedInts; + + class Test { + int compare = UnsignedInts.compare(1, 2); + int divide = UnsignedInts.divide(6, 3); + int remainder = UnsignedInts.remainder(7, 3); + int parse = UnsignedInts.parseUnsignedInt("42"); + } + """, + """ + class Test { + int compare = Integer.compareUnsigned(1, 2); + int divide = Integer.divideUnsigned(6, 3); + int remainder = Integer.remainderUnsigned(7, 3); + int parse = Integer.parseUnsignedInt("42"); + } + """ + ) + ); + } + + @Test + void unsignedLongs() { + //language=java + rewriteRun( + java( + """ + import com.google.common.primitives.UnsignedLongs; + + class Test { + int compare = UnsignedLongs.compare(1L, 2L); + long divide = UnsignedLongs.divide(6L, 3L); + long remainder = UnsignedLongs.remainder(7L, 3L); + long parse = UnsignedLongs.parseUnsignedLong("42"); + } + """, + """ + class Test { + int compare = Long.compareUnsigned(1L, 2L); + long divide = Long.divideUnsigned(6L, 3L); + long remainder = Long.remainderUnsigned(7L, 3L); + long parse = Long.parseUnsignedLong("42"); + } + """ + ) + ); + } +} From 1afc6f9845b877d9508d2d21372b834eba8b6150 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 26 Jul 2026 23:26:51 +0200 Subject: [PATCH 2/3] Drop nonexistent Guava methods from recipe descriptions None of `UnsignedInts`/`UnsignedLongs#compareUnsigned`, `#divideUnsigned` or `IntMath#addExact`/`#subtractExact`/`#multiplyExact` exist in Guava, so naming them as the "instead of" source was misleading. The Subtract and Multiply descriptions also referenced `com.google.common.primitives.IntMath`, a package that does not exist; the class is `com.google.common.math.IntMath`. Descriptions only; the underlying method patterns were already correct for the Math recipes. --- .../resources/META-INF/rewrite/no-guava.yml | 26 +++++-------------- .../resources/META-INF/rewrite/recipes.csv | 14 +++++----- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/no-guava.yml b/src/main/resources/META-INF/rewrite/no-guava.yml index 20e5e30db3..729ae4c131 100644 --- a/src/main/resources/META-INF/rewrite/no-guava.yml +++ b/src/main/resources/META-INF/rewrite/no-guava.yml @@ -363,9 +363,7 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferIntegerCompareUnsigned displayName: Prefer `Integer#compareUnsigned` -description: >- - Prefer `java.lang.Integer#compareUnsigned` instead of using `com.google.common.primitives.UnsignedInts#compare` or - `com.google.common.primitives.UnsignedInts#compareUnsigned`. +description: Prefer `java.lang.Integer#compareUnsigned` instead of using `com.google.common.primitives.UnsignedInts#compare`. tags: - guava preconditions: @@ -382,9 +380,7 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferIntegerDivideUnsigned displayName: Prefer `Integer#divideUnsigned` -description: >- - Prefer `java.lang.Integer#divideUnsigned` instead of using `com.google.common.primitives.UnsignedInts#divide` or - `com.google.common.primitives.UnsignedInts#divideUnsigned`. +description: Prefer `java.lang.Integer#divideUnsigned` instead of using `com.google.common.primitives.UnsignedInts#divide`. tags: - guava preconditions: @@ -432,9 +428,7 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferLongCompareUnsigned displayName: Prefer `Long#compareUnsigned` -description: >- - Prefer `java.lang.Long#compareUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#compare` or - `com.google.common.primitives.UnsignedLongs#compareUnsigned`. +description: Prefer `java.lang.Long#compareUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#compare`. tags: - guava preconditions: @@ -450,9 +444,7 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferLongDivideUnsigned displayName: Prefer `Long#divideUnsigned` -description: >- - Prefer `java.lang.Long#divideUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#divide` or - `com.google.common.primitives.UnsignedLongs#divideUnsigned`. +description: Prefer `java.lang.Long#divideUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#divide`. tags: - guava preconditions: @@ -500,7 +492,7 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferMathAddExact displayName: Prefer `Math#addExact` -description: Prefer `java.lang.Math#addExact` instead of using `com.google.common.math.IntMath#checkedAdd` or `com.google.common.math.IntMath#addExact`. +description: Prefer `java.lang.Math#addExact` instead of using `com.google.common.math.IntMath#checkedAdd`. tags: - guava preconditions: @@ -517,9 +509,7 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferMathSubtractExact displayName: Prefer `Math#subtractExact` -description: >- - Prefer `java.lang.Math#subtractExact` instead of using `com.google.common.primitives.IntMath#checkedSubtract` - or `com.google.common.primitives.IntMath#subtractExact`. +description: Prefer `java.lang.Math#subtractExact` instead of using `com.google.common.math.IntMath#checkedSubtract`. tags: - guava preconditions: @@ -536,9 +526,7 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferMathMultiplyExact displayName: Prefer `Math#multiplyExact` -description: >- - Prefer `java.lang.Math#multiplyExact` instead of using `com.google.common.primitives.IntMath#checkedMultiply` - or `com.google.common.primitives.IntMath#multiplyExact`. +description: Prefer `java.lang.Math#multiplyExact` instead of using `com.google.common.math.IntMath#checkedMultiply`. tags: - guava preconditions: diff --git a/src/main/resources/META-INF/rewrite/recipes.csv b/src/main/resources/META-INF/rewrite/recipes.csv index 89df13325c..e3ee9cf6a3 100644 --- a/src/main/resources/META-INF/rewrite/recipes.csv +++ b/src/main/resources/META-INF/rewrite/recipes.csv @@ -170,8 +170,8 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.g maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.NoMapsAndSetsWithExpectedSize,Prefer JDK methods for Maps and Sets of an expected size,Prefer Java 19+ methods to create Maps and Sets of an expected size instead of using Guava methods.,1,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferCharCompare,Prefer `java.lang.Char#compare`,Prefer `java.lang.Char#compare` instead of using `com.google.common.primitives.Chars#compare`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerCompare,Prefer `Integer#compare`,Prefer `java.lang.Integer#compare` instead of using `com.google.common.primitives.Ints#compare`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerCompareUnsigned,Prefer `Integer#compareUnsigned`,Prefer `java.lang.Integer#compareUnsigned` instead of using `com.google.common.primitives.UnsignedInts#compare` or `com.google.common.primitives.UnsignedInts#compareUnsigned`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerDivideUnsigned,Prefer `Integer#divideUnsigned`,Prefer `java.lang.Integer#divideUnsigned` instead of using `com.google.common.primitives.UnsignedInts#divide` or `com.google.common.primitives.UnsignedInts#divideUnsigned`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerCompareUnsigned,Prefer `Integer#compareUnsigned`,Prefer `java.lang.Integer#compareUnsigned` instead of using `com.google.common.primitives.UnsignedInts#compare`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerDivideUnsigned,Prefer `Integer#divideUnsigned`,Prefer `java.lang.Integer#divideUnsigned` instead of using `com.google.common.primitives.UnsignedInts#divide`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerParseUnsignedInt,Prefer `Integer#parseUnsignedInt`,Prefer `java.lang.Integer#parseUnsignedInt` instead of using `com.google.common.primitives.UnsignedInts#parseUnsignedInt`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferIntegerRemainderUnsigned,Prefer `Integer#remainderUnsigned`,Prefer `java.lang.Integer#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedInts#remainder`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferJavaNioCharsetStandardCharsets,Prefer `java.nio.charset.StandardCharsets`,Prefer `java.nio.charset.StandardCharsets` instead of using `com.google.common.base.Charsets`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, @@ -188,14 +188,14 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.g maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferJavaUtilPredicate,Prefer `java.util.function.Predicate`,Prefer `java.util.function.Predicate` instead of using `com.google.common.base.Predicate`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferJavaUtilSupplier,Prefer `java.util.function.Supplier`,Prefer `java.util.function.Supplier` instead of using `com.google.common.base.Supplier`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongCompare,Prefer `Long#compare`,Prefer `java.lang.Long#compare` instead of using `com.google.common.primitives.Longs#compare`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongCompareUnsigned,Prefer `Long#compareUnsigned`,Prefer `java.lang.Long#compareUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#compare` or `com.google.common.primitives.UnsignedLongs#compareUnsigned`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongDivideUnsigned,Prefer `Long#divideUnsigned`,Prefer `java.lang.Long#divideUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#divide` or `com.google.common.primitives.UnsignedLongs#divideUnsigned`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongCompareUnsigned,Prefer `Long#compareUnsigned`,Prefer `java.lang.Long#compareUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#compare`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongDivideUnsigned,Prefer `Long#divideUnsigned`,Prefer `java.lang.Long#divideUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#divide`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongParseUnsignedLong,Prefer `Long#parseUnsignedLong`,Prefer `java.lang.Long#parseUnsignedLong` instead of using `com.google.common.primitives.UnsignedLongs#parseUnsignedLong`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferLongRemainderUnsigned,Prefer `Long#remainderUnsigned`,Prefer `java.lang.Long#remainderUnsigned` instead of using `com.google.common.primitives.UnsignedLongs#remainder`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathAddExact,Prefer `Math#addExact`,Prefer `java.lang.Math#addExact` instead of using `com.google.common.math.IntMath#checkedAdd` or `com.google.common.math.IntMath#addExact`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathAddExact,Prefer `Math#addExact`,Prefer `java.lang.Math#addExact` instead of using `com.google.common.math.IntMath#checkedAdd`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathClamp,Prefer `Math#clamp`,Prefer `java.lang.Math#clamp` instead of using `com.google.common.primitives.*#constrainToRange`.,7,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathMultiplyExact,Prefer `Math#multiplyExact`,Prefer `java.lang.Math#multiplyExact` instead of using `com.google.common.primitives.IntMath#checkedMultiply` or `com.google.common.primitives.IntMath#multiplyExact`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathSubtractExact,Prefer `Math#subtractExact`,Prefer `java.lang.Math#subtractExact` instead of using `com.google.common.primitives.IntMath#checkedSubtract` or `com.google.common.primitives.IntMath#subtractExact`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathMultiplyExact,Prefer `Math#multiplyExact`,Prefer `java.lang.Math#multiplyExact` instead of using `com.google.common.math.IntMath#checkedMultiply`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferMathSubtractExact,Prefer `Math#subtractExact`,Prefer `java.lang.Math#subtractExact` instead of using `com.google.common.math.IntMath#checkedSubtract`.,3,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.guava.PreferShortCompare,Prefer `Short#compare`,Prefer `java.lang.Short#compare` instead of using `com.google.common.primitives.Shorts#compare`.,2,,Guava,Modernize,Java,,Recipes for migrating from [Google Guava](https://github.com/google/guava) to Java standard library.,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.io.AddInputStreamBulkReadMethod,Add bulk read method to `InputStream` implementations,"Adds a `read(byte[], int, int)` method to `InputStream` subclasses that only override the single-byte `read()` method. Java's default `InputStream.read(byte[], int, int)` implementation calls the single-byte `read()` method in a loop, which can cause severe performance degradation (up to 350x slower) for bulk reads. This recipe detects `InputStream` implementations that delegate to another stream and adds the missing bulk read method to delegate bulk reads as well.",1,,`java.io` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.io.ReplaceFileInOrOutputStreamFinalizeWithClose,Replace invocations of `finalize()` on `FileInputStream` and `FileOutputStream` with `close()`,Replace invocations of the deprecated `finalize()` method on `FileInputStream` and `FileOutputStream` with `close()`.,1,,`java.io` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, From 4fc2823a0e1012a6dc8b87a2ab444aef8ae3c466 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 26 Jul 2026 23:54:37 +0200 Subject: [PATCH 3/3] Match unsigned methods by name rather than exact parameter types Pinning the exact parameter types is what allowed the earlier mismatches to go unnoticed, so match on `(..)` instead, as the sibling `PreferMath*Exact` recipes already do. `UnsignedInts` and `UnsignedLongs` each declare a single overload of `compare`, `divide` and `remainder`, and those signatures have been unchanged since the classes were introduced in Guava 10.0/11.0, so this cannot over-match. Also cover the two-argument radix overloads of `parseUnsignedInt` and `parseUnsignedLong`, and add the missing blank line before `PreferLongDivideUnsigned`. --- .../resources/META-INF/rewrite/no-guava.yml | 25 ++++++++++--------- .../migrate/guava/NoGuavaUnsignedTest.java | 24 ++++++++++++++++++ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/no-guava.yml b/src/main/resources/META-INF/rewrite/no-guava.yml index 729ae4c131..ebef7d0c61 100644 --- a/src/main/resources/META-INF/rewrite/no-guava.yml +++ b/src/main/resources/META-INF/rewrite/no-guava.yml @@ -370,10 +370,10 @@ preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodName: - methodPattern: com.google.common.primitives.UnsignedInts compare(int, int) + methodPattern: com.google.common.primitives.UnsignedInts compare(..) newMethodName: compareUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedInts compareUnsigned(int, int) + methodPattern: com.google.common.primitives.UnsignedInts compareUnsigned(..) fullyQualifiedTargetTypeName: java.lang.Integer --- @@ -387,10 +387,10 @@ preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodName: - methodPattern: com.google.common.primitives.UnsignedInts divide(int, int) + methodPattern: com.google.common.primitives.UnsignedInts divide(..) newMethodName: divideUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedInts divideUnsigned(int, int) + methodPattern: com.google.common.primitives.UnsignedInts divideUnsigned(..) fullyQualifiedTargetTypeName: java.lang.Integer --- @@ -418,10 +418,10 @@ preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodName: - methodPattern: com.google.common.primitives.UnsignedInts remainder(int, int) + methodPattern: com.google.common.primitives.UnsignedInts remainder(..) newMethodName: remainderUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedInts remainderUnsigned(int, int) + methodPattern: com.google.common.primitives.UnsignedInts remainderUnsigned(..) fullyQualifiedTargetTypeName: java.lang.Integer --- @@ -435,11 +435,12 @@ preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodName: - methodPattern: com.google.common.primitives.UnsignedLongs compare(long, long) + methodPattern: com.google.common.primitives.UnsignedLongs compare(..) newMethodName: compareUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedLongs compareUnsigned(long, long) + methodPattern: com.google.common.primitives.UnsignedLongs compareUnsigned(..) fullyQualifiedTargetTypeName: java.lang.Long + --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.guava.PreferLongDivideUnsigned @@ -451,10 +452,10 @@ preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodName: - methodPattern: com.google.common.primitives.UnsignedLongs divide(long, long) + methodPattern: com.google.common.primitives.UnsignedLongs divide(..) newMethodName: divideUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedLongs divideUnsigned(long, long) + methodPattern: com.google.common.primitives.UnsignedLongs divideUnsigned(..) fullyQualifiedTargetTypeName: java.lang.Long --- @@ -482,10 +483,10 @@ preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodName: - methodPattern: com.google.common.primitives.UnsignedLongs remainder(long, long) + methodPattern: com.google.common.primitives.UnsignedLongs remainder(..) newMethodName: remainderUnsigned - org.openrewrite.java.ChangeMethodTargetToStatic: - methodPattern: com.google.common.primitives.UnsignedLongs remainderUnsigned(long, long) + methodPattern: com.google.common.primitives.UnsignedLongs remainderUnsigned(..) fullyQualifiedTargetTypeName: java.lang.Long --- diff --git a/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaUnsignedTest.java b/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaUnsignedTest.java index 725c18bda6..f27a4c5e82 100644 --- a/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaUnsignedTest.java +++ b/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaUnsignedTest.java @@ -60,6 +60,30 @@ class Test { ); } + @Test + void radixOverloads() { + //language=java + rewriteRun( + java( + """ + import com.google.common.primitives.UnsignedInts; + import com.google.common.primitives.UnsignedLongs; + + class Test { + int i = UnsignedInts.parseUnsignedInt("ff", 16); + long l = UnsignedLongs.parseUnsignedLong("ff", 16); + } + """, + """ + class Test { + int i = Integer.parseUnsignedInt("ff", 16); + long l = Long.parseUnsignedLong("ff", 16); + } + """ + ) + ); + } + @Test void unsignedLongs() { //language=java