[Gradle] Clone Properties before iterating over them as it can cause...

...ConcurrentModificationException if someone will concurrently
 modify them
This commit is contained in:
Anton Lakotka
2022-12-15 18:58:41 +01:00
committed by Space Team
parent f5d4984274
commit ba20972449
@@ -137,8 +137,8 @@ abstract class KotlinToolRunner(
val transformedArgs = transformArgs(args) val transformedArgs = transformArgs(args)
val classpath = executionContext.filesProvider(classpath) val classpath = executionContext.filesProvider(classpath)
val systemProperties = System.getProperties() val systemProperties = System.getProperties()
/* Capture 'System.getProperties()' as List to avoid potential 'ConcurrentModificationException' */ /* Capture 'System.getProperties()' current state to avoid potential 'ConcurrentModificationException' */
.toListSynchronized() .snapshot()
.asSequence() .asSequence()
.map { (k, v) -> k.toString() to v.toString() } .map { (k, v) -> k.toString() to v.toString() }
.filter { (k, _) -> k !in execSystemPropertiesBlacklist } .filter { (k, _) -> k !in execSystemPropertiesBlacklist }
@@ -226,9 +226,6 @@ abstract class KotlinToolRunner(
else -> this else -> this
} }
/** private fun Properties.snapshot(): Properties = clone() as Properties
* Safely enter the [Properties] monitor and capture the current values
*/
private fun Properties.toListSynchronized(): List<Pair<Any, Any>> = synchronized(this) { toList() }
} }
} }