Remove method invocations | OpenRewrite Docs
org.openrewrite.java.RemoveMethodInvocations
Remove method invocations if syntactically safe.
Recipe source
GitHub: RemoveMethodInvocations.java, Issue Tracker, Maven Central
This recipe is available under the Apache License Version 2.0.
Options
| Type | Name | Description | Example |
|---|---|---|---|
String | methodPattern | A pattern to match method invocations for removal. A method pattern is used to find matching method invocations. For example, to find all method invocations in the Guava library, use the pattern: com.google.common..*#*(..).The pattern format is
For more specific queries, like Guava's | java.lang.StringBuilder append(java.lang.String) |
Used by
This recipe is used as part of the following composite recipes:
- Avoid using the deprecated empty
finalize()method injava.desktop - Migrate Spring Boot 3.4 deprecated classes and methods
- Migrate deprecated path mapping options
- Migrate from EasyMock to Mockito
- Migrate to Apache HttpCore Nio Classes to Apache HttpCore 5.x
- Migrate to Java 11
- Migrate to Java 17
- Migrate to Java 17
- Migrate to Java 8
- Migrate to Spring Framework 6.1
- Migrate to Spring ORM to 5
- Remove Security AccessController
- Remove Security Policy
- Remove Security SecurityManager
- Remove
Runtime.traceInstructions(boolean)andRuntime.traceMethodCallsmethods - Remove
Thread.countStackFrames()method - Remove
Thread.destroy()andThread.stop(Throwable) - Remove
getCommentandgetVersionmethods - Remove path extension content negotiation methods
- Replace Removed WebLogicJtaTransactionManager from Spring Framework 5.3.x to 6.2.x
- Resolve Deprecations in Spring Boot 3.3
Usage
This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly (unless you are running them via the Moderne CLI). To activate this recipe you must create a new recipe which fills in the required parameters. In your rewrite.yml create a new recipe with a unique name. For example: com.yourorg.RemoveMethodInvocationsExample.
Here's how you can define and customize such a recipe within your rewrite.yml:
rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.RemoveMethodInvocationsExample
displayName: Remove method invocations example
recipeList:
- org.openrewrite.java.RemoveMethodInvocations:
methodPattern: java.lang.StringBuilder append(java.lang.String)
This recipe has no required configuration parameters and comes from a rewrite core library. It can be activated directly without adding any dependencies.
Now that com.yourorg.RemoveMethodInvocationsExample has been defined, activate it in your build file:
- Gradle
- Maven POM
- Moderne CLI
- Add the following to your
build.gradlefile:build.gradle
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("com.yourorg.RemoveMethodInvocationsExample")
setExportDatatables(true)
}
repositories {
mavenCentral()
} - Run
gradle rewriteRunto run the recipe.
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform 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.
Data Tables
- SourcesFileResults
- SearchResults
- SourcesFileErrors
- RecipeRunStats
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
| Column Name | Description |
|---|---|
| Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
| Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
| Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
| Recipe that made changes | The specific recipe that made a change. |
| Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
| Cycle | The recipe cycle in which the change was made. |