# ConcurrentModification exception on Java 8 for plugins.withId() with Gradle 2.4+

**URL:** <https://discuss.gradle.org/t/concurrentmodification-exception-on-java-8-for-plugins-withid-with-gradle-2-4/8928>\
**Category:** Bugs\
**Tags:** issue-resolved\
**Created:** [April 13, 2015, 4:22pm UTC](https://discuss.gradle.org/t/concurrentmodification-exception-on-java-8-for-plugins-withid-with-gradle-2-4/8928 "2015-04-13T16:22:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Miller](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jason_miller/32/552_2.png) [@Jason\_Miller](https://discuss.gradle.org/u/Jason_Miller)\
**Post date:** [April 13, 2015, 4:22pm UTC](https://discuss.gradle.org/t/concurrentmodification-exception-on-java-8-for-plugins-withid-with-gradle-2-4/8928/1 "2015-04-13T16:22:18Z")

</div>

Using Gradle-2.4-20150408220020, also occurs with Gradle-2.5-20150413031218. Does not occur with Gradle 2.3.

Seems to be caused by calling hasPlugin() for most plugins from multiple plugins.withId{} blocks, occurs with both the PluginContainer and PluginManager APIs, and appears to only trigger when running Gradle with Java 8. Exception doesn’t occur until plugins are actually applied, and appears to be order-dependent, e.g. if ‘ivy-publish’ is applied first the exception doesn’t happen.

[Example project here](https://github.com/stormbeta/gradle-bug-examples/tree/gradle-2.4-bug).

```
package com.example

import org.gradle.api.Plugin
import org.gradle.api.Project

class ExamplePlugin implements Plugin<Project> {
  void apply(final Project project) {
    project.plugins.withId('ivy-publish') {
      project.plugins.hasPlugin('jacoco')
    }
    //Works if:
    //this part is removed
    //or ivy-publish is applied before ExamplePlugin
    //or build with Java 7 instead of Java 8
    //or build with Gradle 2.3 instead of 2.4/2.5
    project.plugins.withId('maven-publish') {
      project.plugins.hasPlugin('jacoco')
    }
  }
}

```

Side note - the new forums appear to be unreasonably picky about thread titles - I had to deliberately obfuscate the title wording to get it to accept.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [April 14, 2015, 11:42pm UTC](https://discuss.gradle.org/t/concurrentmodification-exception-on-java-8-for-plugins-withid-with-gradle-2-4/8928/2 "2015-04-14T23:42:41Z")

</div>

Thanks for the report, this has been fixed for 2.4.

---

<div class="post-metadata">

**Author:** ![Jason\_Miller](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jason_miller/32/552_2.png) [@Jason\_Miller](https://discuss.gradle.org/u/Jason_Miller)\
**Post date:** [April 17, 2015, 5:01pm UTC](https://discuss.gradle.org/t/concurrentmodification-exception-on-java-8-for-plugins-withid-with-gradle-2-4/8928/3 "2015-04-17T17:01:35Z")

</div>

Confirmed this is fixed in the more recent 2.4 snapshots, thanks!
