Skip to content

Commit

Permalink
Fix possible ConcurrentModificationException when collection inform…
Browse files Browse the repository at this point in the history
…ation in `FinalFields` and `MethodIds` (#354)



Fixes #353
  • Loading branch information
ndkoval authored Aug 9, 2024
1 parent b821594 commit ba0b605
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
package org.jetbrains.kotlinx.lincheck.transformation

import org.jetbrains.kotlinx.lincheck.transformation.FinalFields.FieldInfo.*
import org.jetbrains.kotlinx.lincheck.transformation.FinalFields.FinalFieldsVisitor
import org.jetbrains.kotlinx.lincheck.transformation.FinalFields.addFinalField
import org.jetbrains.kotlinx.lincheck.transformation.FinalFields.addMutableField
import org.jetbrains.kotlinx.lincheck.transformation.FinalFields.collectFieldInformation
import org.jetbrains.kotlinx.lincheck.transformation.FinalFields.isFinalField
import org.objectweb.asm.*
import java.util.concurrent.ConcurrentHashMap

/**
* [CodeLocations] object is used to maintain the mapping between unique IDs and code locations.
Expand Down Expand Up @@ -63,6 +63,7 @@ internal object MethodIds {

private val map: MutableMap<String, Int> = hashMapOf()

@Synchronized
fun getMethodId(owner: String, name: String, desc: String): Int {
return map.computeIfAbsent("$owner:$name:$desc") { map.size + 1 }
}
Expand All @@ -88,7 +89,7 @@ internal object FinalFields {
/**
* Stores a map INTERNAL_CLASS_NAME -> { FIELD_NAME -> IS FINAL } for each processed class.
*/
private val classToFieldsMap = HashMap<String, HashMap<String, FieldInfo>>()
private val classToFieldsMap = ConcurrentHashMap<String, HashMap<String, FieldInfo>>()

/**
* Registers the field [fieldName] as a final field of the class [internalClassName].
Expand Down

0 comments on commit ba0b605

Please sign in to comment.