Use double-checked locking in some reflection internals

Note that `volatile` is not needed because in both cases we initialize
an object with a final field, which is subject to safe initialization.
This commit is contained in:
Alexander Udalov
2021-07-28 21:09:48 +02:00
parent e20b354dbd
commit 5f7803f2db
2 changed files with 5 additions and 10 deletions
@@ -86,10 +86,8 @@ private object Java8RepeatableContainerLoader {
}
fun loadRepeatableContainer(klass: Class<out Annotation>): Class<out Annotation>? {
var cache = cache
if (cache == null) {
cache = buildCache()
this.cache = cache
val cache = cache ?: synchronized(this) {
cache ?: buildCache().also { cache = it }
}
val repeatableClass = cache.repeatableClass ?: return null