Skip to content

ConcurrentModificationException when filtering converted Java HashMap - regression #7269

Description

@scabug

Filtering a wrapped Java map throws ConcurrentModificationException. This did not happen in Scala 2.9, but happens in 2.10, including 2.10.1. In the example below call to retain results in exception.

package issues.issueXX

import org.scalatest.FlatSpec
import scala.collection.JavaConversions._
import scala.collection.mutable

class MapRetainSpec extends FlatSpec {

  "Scala Map conversion" should "support 'retain'" in {
    val mapJ = new java.util.HashMap[Int, String]
    val mapS: mutable.Map[Int, String] = mapJ

    (10 to 20).foreach(i => mapS += ((i, i.toString)))
    assert(11 === mapS.size)

    // ConcurrentModificationException thrown in the following line 
    mapS.retain((i, str) => i % 2 == 0)
    assert(6 === mapS.size)
  }
}

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions