Hopefully the forum thinks this is a valid title?

Real title : Iterating filtered TaskCollection causes ConcurrentModificationException

I am completely baffled as to why this throws CME:

task showTestTaskDetails {
    doLast {
        project.tasks.withType( Test ).each { task ->
            ...
            logger.lifecycle( "  > Test classpath : {}", task.classpath.asPath )
            ...
        }
    }
}

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':showTestTaskDetails'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:207)
        ...
Caused by: java.util.ConcurrentModificationException
        at org.gradle.api.internal.collections.FilteredCollection$FilteringIterator.findNext(FilteredCollection.java:121)
        at org.gradle.api.internal.collections.FilteredCollection$FilteringIterator.next(FilteredCollection.java:140)
        at org.gradle.api.internal.DefaultDomainObjectCollection$IteratorImpl.next(DefaultDomainObjectCollection.java:479)
        ...

Any ideas?

I added the code from your question to a clean java-application project (https://github.com/bennofs/repros/tree/gradle-test-tasks-cme) and gradle showTestTaskDetails runs successfully on this setup:

------------------------------------------------------------
Gradle 6.6
------------------------------------------------------------

Build time:   2020-08-24 18:57:56 UTC
Revision:     <unknown>

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          14.0.2 (Oracle Corporation 14.0.2+12)
OS:           Linux 5.8.6-arch1-1 amd64

So something must be different in your setup that causes the failure, but I don’t see any info about that in your question.

------------------------------------------------------------
Gradle 6.5.1
------------------------------------------------------------

Build time:   2020-06-30 06:32:47 UTC
Revision:     66bc713f7169626a7f0134bf452abde51550ea0a

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.6 (AdoptOpenJDK 11.0.6+10)
OS:           Linux 5.6.19-300.fc32.x86_64 amd64

I also just tried with 6.6 - same error.

The only way I could get it to work was to change project.tasks.withType( Test ).each to project.tasks.each