diff --git a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaRefaster.java b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaRefaster.java index 37db830d96..562f63ad8f 100644 --- a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaRefaster.java +++ b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaRefaster.java @@ -41,36 +41,36 @@ Object after(Object object) { } } + // Note: Order of the below two recipes are important. @RecipeDescriptor( - name = "`Preconditions.checkNotNull` with message to `Objects.requireNonNull`", + name = "`Preconditions.checkNotNull` with `String` message to `Objects.requireNonNull`", description = "Migrate from Guava `Preconditions.checkNotNull` to Java 8 `java.util.Objects.requireNonNull`." ) public static class PreconditionsCheckNotNullWithMessageToObjectsRequireNonNull { @BeforeTemplate - Object before(Object object, Object message) { + Object before(Object object, String message) { return com.google.common.base.Preconditions.checkNotNull(object, message); } @AfterTemplate - Object after(Object object, Object message) { - return java.util.Objects.requireNonNull(object, String.valueOf(message)); + Object after(Object object, String message) { + return java.util.Objects.requireNonNull(object, message); } } @RecipeDescriptor( - name = "`String.valueof(String)` to `String`", - description = "Migrate from `String.valueof(String)` to `String`, mainly as a cleanup after other recipes." + name = "`Preconditions.checkNotNull` with `Object` message to `Objects.requireNonNull` with `String.valueOf`", + description = "Migrate from Guava `Preconditions.checkNotNull` to Java 8 `java.util.Objects.requireNonNull`." ) - public static class StringValueOfString { + public static class PreconditionsCheckNotNullWithMessageToObjectsRequireNonNullMessageTypeObject { @BeforeTemplate - @SuppressWarnings("UnnecessaryCallToStringValueOf") - String before(String string) { - return String.valueOf(string); + Object before(Object object, Object message) { + return com.google.common.base.Preconditions.checkNotNull(object, message); } @AfterTemplate - String after(String string) { - return (string); + Object after(Object object, Object message) { + return java.util.Objects.requireNonNull(object, String.valueOf(message)); } } }