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

**URL:** <https://discuss.gradle.org/t/abstractcopytask-rename-closure-does-not-handle-null-returns-as-documented/19758>\
**Category:** Bugs\
**Tags:** issue-acknowledged, gradle-3568\
**Created:** [September 27, 2016, 11:58pm UTC](https://discuss.gradle.org/t/abstractcopytask-rename-closure-does-not-handle-null-returns-as-documented/19758 "2016-09-27T23:58:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blaine\_simpson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/blaine_simpson/32/9110_2.png) [@blaine\_simpson](https://discuss.gradle.org/u/blaine_simpson)\
**Post date:** [September 27, 2016, 11:58pm UTC](https://discuss.gradle.org/t/abstractcopytask-rename-closure-does-not-handle-null-returns-as-documented/19758/1 "2016-09-27T23:58:08Z")

</div>

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)](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.

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

```

---

<div class="post-metadata">

**Author:** ![jendrik](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jendrik/32/7964_2.png) [@jendrik](https://discuss.gradle.org/u/jendrik)\
**Post date:** [September 28, 2016, 2:08pm UTC](https://discuss.gradle.org/t/abstractcopytask-rename-closure-does-not-handle-null-returns-as-documented/19758/2 "2016-09-28T14:08:05Z")

</div>

Hi Blaine,

Thanks for reporting! That’s indeed not correct. I opened a bug:  
[https://issues.gradle.org/browse/GRADLE-3568](https://issues.gradle.org/browse/GRADLE-3568)
