[GRADLE-2512] Provide a better error message when trying to add an action to an already executing task Created: 08/Oct/12  Updated: 07/May/13  Resolved: 14/Nov/12

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.4-rc-1

Type: Improvement
Reporter: Szczepan Faber Assignee: Unassigned
Resolution: Fixed Votes: 0

Issue Links:
Duplicate
Duplicated by GRADLE-917 ConcurrentModificationException in De... Resolved

 Description   
task foo << {
  doLast { println 'foo' }
}

Above is a user mistake easy to make. However, the error message not very friendly (ConcurrentModificationException). I'd expect to see something like: 'you cannot add task action at configuration time, please check if ...'



 Comments   
Comment by Adam Murdoch [ 12/Nov/12 ]

Doing any of the following after the task has started executing should be deprecated and result in a warning:

  • Mutating Task.getActions().
  • Calling Task.setActions().
  • Calling Task.dependsOn(), Task.setDependsOn().
  • Calling Task.onlyIf(), Task.setOnlyIf().
  • Calling Task.doLast(), Task.doFirst(), Task.leftShift().
  • Calling Task.setEnabled().
  • Calling TaskInputs.files().
  • Calling TaskInputs.dir().
  • Calling TaskInputs.property(), TaskInputs.properties().
  • Calling TaskInputs.source(), sourceDir().
  • Calling TaskOutputs.upToDateWhen().
  • Calling TaskOutputs.files()
  • Calling TaskOutputs.dir().
Comment by Szczepan Faber [ 13/Nov/12 ]

Awesome. I vote for making the exception message descriptive and hinting. I would even mention in the message that typically this problem often appears for misused '<<' at task declaration.

Comment by René Gröschke (Inactive) [ 14/Nov/12 ]

I added warnings for all cases above + TaskInputs.file() & TaskOutputs.file(). You can lookup the warning messages in the according integration test class 'ExecutionTimeTaskConfigurationIntegrationTest'

Generated at Wed Jun 30 12:23:59 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.