When call Java method in Gradle Kotlin DSL: Argument type mismatch: actual type is 'kotlin.String?', but '@Nullable() kotlin.String' was expected

I’m using the file filter in jar task to remove some SPI.

filesMatching("inst/META-INF/services/*") {
  filter { line ->
    if (line.startsWith("com.example.")) {
      null
    } else {
      line
    }
  }
}

The signature of the Java method is:
ContentFilterable filter(Transformer<@org.jetbrains.annotations.Nullable String, String> transformer);, which receive a Transformer<@org.jetbrains.annotations.Nullable String, String> as parameter. And in the method, the returned null is important, which meas that the line should be removed.
I passed a lambda that returns String?. It works, but an error will be reported by IDEA and a warning will be reported by Gradle, which is noisy. How can I avoid those?

1 Like