Replace org.apache.commons.lang3.Validate#notNull with Objects#requireNonNull
org.openrewrite.java.cleanup.ReplaceValidateNotNullHavingSingleArgWithObjectsRequireNonNull Replace
org.apache.commons.lang3.Validate.notNull(Object)
with Objects.requireNonNull(Object)
.- groupId: org.openrewrite
- artifactId: rewrite-java
- version: 7.38.0
This recipe has no required configuration parameters and comes from a rewrite core library. It can be activated directly without adding any dependencies.
Gradle
Maven POM
Maven Command Line
build.gradle
plugins {
id("org.openrewrite.rewrite") version("5.38.0")
}
rewrite {
activeRecipe("org.openrewrite.java.cleanup.ReplaceValidateNotNullHavingSingleArgWithObjectsRequireNonNull")
}
repositories {
mavenCentral()
}
pom.xml
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>4.42.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.cleanup.ReplaceValidateNotNullHavingSingleArgWithObjectsRequireNonNull</recipe>
</activeRecipes>
</configuration>
</plugin>
</plugins>
</build>
</project>
shell
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.activeRecipes=org.openrewrite.java.cleanup.ReplaceValidateNotNullHavingSingleArgWithObjectsRequireNonNull
Recipe List
Yaml Recipe List
- methodPattern:
org.apache.commons.lang3.Validate notNull(Object)
- newMethodName:
requireNonNull
- methodPattern:
org.apache.commons.lang3.Validate requireNonNull(Object)
- fullyQualifiedTargetTypeName:
java.util.Objects
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.cleanup.ReplaceValidateNotNullHavingSingleArgWithObjectsRequireNonNull
displayName: Replace `org.apache.commons.lang3.Validate#notNull` with `Objects#requireNonNull`
description: Replace `org.apache.commons.lang3.Validate.notNull(Object)` with `Objects.requireNonNull(Object)`.
recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.apache.commons.lang3.Validate notNull(Object)
newMethodName: requireNonNull
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.apache.commons.lang3.Validate requireNonNull(Object)
fullyQualifiedTargetTypeName: java.util.Objects
The Moderne public SaaS instance enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.