Task replace actions

Why does Task.replace() method keep old defined actions. Documentation says it will replace any existing task. It obviously doesn’t do that.

For example if I use

tasks.register("taskToBeReplaced") {
  doLast {
    println("Action Old")
  }
}

tasks.replace("taskToBeReplaced").configure {
  doLast {
    print("Action New")
  }
}

Result is

> Task :taskToBeReplaced
Action Old
Action New

You see action of the replaced method is still present!

But if I add actions.clear() command in configuration block of replaced task then the result is as expected

tasks.register("taskToBeReplaced") {
  doLast {
    println("Action Old")
  }
}

tasks.replace("taskToBeReplaced").configure {
  actions.clear()
  doLast {
    print("Action New")
  }
}

Result:

> Task :taskToBeReplaced
Action New

I am using gradle wrapper 6.8.2, am I missing something. Documentation clearly says replace, I am assuming everything is replaced from the old task including a list of actions.

As then I can use following existing task and reconfigure it.

tasks.getByPath("taskToBeReplaced").configure {
  actions.clear()
  doLast {
    print("Action New")
  }
}

And Task.replace() method becomes obsolete.