AbstractCopyTask.rename(Closure) does not handle null returns as documented

See what the 3.1 API docs says about the closure returning nulls: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/AbstractCopyTask.html#rename(groovy.lang.Closure) : The closure may return null, in which case the original name will be used.

Instead, when I return null I get an NPE. The diagnostics are particularly bad. Using --debug and --stacktrace I can find no indication of the triggering location in my build.gradle file. Every line in the stack trace is a Gradle method location. (Perhaps my lines are in the “68 more” that were truncated).

I can, of course, return ‘it’, but how un-Groovy to rename a file to its original name.

task cp(type: Copy) {
    from file('sd1')
    into file('sdO')
    //rename { println it; "_${it}_" }
    rename { null }

Hi Blaine,

Thanks for reporting! That’s indeed not correct. I opened a bug: