Add @Nullable to a functional-interface return type argument fed a null-returning lambda
io.moderne.nullability.AddNullableToFunctionalReturnArgumentArtifactio.moderne.recipe:rewrite-nullabilityWhen a null-returning lambda is passed for a functional-interface parameter (such as Function<R, T>) of a method that consumes the produced value in a null-tolerant way, annotates that interface's return type argument @Nullable (Function<R, @Nullable T>) so returning null through the callback is legal under JSpecify/NullAway. This is distinct from widening a pass-through type-parameter bound (handled separately); a de-overlap guard keeps the two from both firing. Only parameters of recognized functional interfaces, on methods declared in the working set, are changed; already-@Nullable and wildcard/raw arguments are left untouched.
Add to your build
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("io.moderne.nullability.AddNullableToFunctionalReturnArgument")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("io.moderne.recipe:rewrite-nullability:0.6.0")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe io.moderne.nullability.AddNullableToFunctionalReturnArgumentIf the recipe isn’t available locally, install it with:
mod config recipes jar install io.moderne.recipe:rewrite-nullability:RELEASEData tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats