From 042a8ff6a2cadd8c2e8c156970283d4a28609549 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 4 Jul 2018 06:36:09 +0300 Subject: [PATCH] Provide ThreadLocalRandom wrapper only on JDK8 as it is buggy in JDK7 --- .../jdk7/JDK7PlatformImplementations.kt | 4 ---- .../random/jdk7/PlatformThreadLocalRandom.kt | 19 ------------------ .../jdk8/JDK8PlatformImplementations.kt | 4 ++++ .../random/jdk8/PlatformThreadLocalRandom.kt | 20 +++++++++++++++++++ 4 files changed, 24 insertions(+), 23 deletions(-) delete mode 100644 libraries/stdlib/jdk7/src/kotlin/random/jdk7/PlatformThreadLocalRandom.kt create mode 100644 libraries/stdlib/jdk8/src/kotlin/random/jdk8/PlatformThreadLocalRandom.kt diff --git a/libraries/stdlib/jdk7/src/kotlin/internal/jdk7/JDK7PlatformImplementations.kt b/libraries/stdlib/jdk7/src/kotlin/internal/jdk7/JDK7PlatformImplementations.kt index 1146bbdf609..5cce9d93f94 100644 --- a/libraries/stdlib/jdk7/src/kotlin/internal/jdk7/JDK7PlatformImplementations.kt +++ b/libraries/stdlib/jdk7/src/kotlin/internal/jdk7/JDK7PlatformImplementations.kt @@ -18,13 +18,9 @@ package kotlin.internal.jdk7 import kotlin.internal.PlatformImplementations -import kotlin.random.Random -import kotlin.random.jdk7.PlatformThreadLocalRandom internal open class JDK7PlatformImplementations : PlatformImplementations() { override fun addSuppressed(cause: Throwable, exception: Throwable) = cause.addSuppressed(exception) - override fun defaultPlatformRandom(): Random = PlatformThreadLocalRandom() - } diff --git a/libraries/stdlib/jdk7/src/kotlin/random/jdk7/PlatformThreadLocalRandom.kt b/libraries/stdlib/jdk7/src/kotlin/random/jdk7/PlatformThreadLocalRandom.kt deleted file mode 100644 index 4fdb91a1b58..00000000000 --- a/libraries/stdlib/jdk7/src/kotlin/random/jdk7/PlatformThreadLocalRandom.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package kotlin.random.jdk7 - -import java.util.concurrent.ThreadLocalRandom - -@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "CANNOT_OVERRIDE_INVISIBLE_MEMBER") -internal class PlatformThreadLocalRandom : kotlin.random.AbstractPlatformRandom() { - override val impl: ThreadLocalRandom get() = ThreadLocalRandom.current() - - override fun nextInt(origin: Int, bound: Int): Int = impl.nextInt(origin, bound) - override fun nextLong(bound: Long): Long = impl.nextLong(bound) - override fun nextLong(origin: Long, bound: Long): Long = impl.nextLong(origin, bound) - override fun nextDouble(bound: Double): Double = impl.nextDouble(bound) - override fun nextDouble(origin: Double, bound: Double): Double = impl.nextDouble(origin, bound) -} \ No newline at end of file diff --git a/libraries/stdlib/jdk8/src/kotlin/internal/jdk8/JDK8PlatformImplementations.kt b/libraries/stdlib/jdk8/src/kotlin/internal/jdk8/JDK8PlatformImplementations.kt index 25f14adbd2d..329e5950699 100644 --- a/libraries/stdlib/jdk8/src/kotlin/internal/jdk8/JDK8PlatformImplementations.kt +++ b/libraries/stdlib/jdk8/src/kotlin/internal/jdk8/JDK8PlatformImplementations.kt @@ -21,6 +21,8 @@ import java.util.regex.MatchResult import java.util.regex.Matcher import kotlin.internal.PlatformImplementations import kotlin.internal.jdk7.JDK7PlatformImplementations +import kotlin.random.Random +import kotlin.random.jdk8.PlatformThreadLocalRandom internal open class JDK8PlatformImplementations : JDK7PlatformImplementations() { @@ -34,4 +36,6 @@ internal open class JDK8PlatformImplementations : JDK7PlatformImplementations() null } + override fun defaultPlatformRandom(): Random = PlatformThreadLocalRandom() + } diff --git a/libraries/stdlib/jdk8/src/kotlin/random/jdk8/PlatformThreadLocalRandom.kt b/libraries/stdlib/jdk8/src/kotlin/random/jdk8/PlatformThreadLocalRandom.kt new file mode 100644 index 00000000000..ee3eb1418e2 --- /dev/null +++ b/libraries/stdlib/jdk8/src/kotlin/random/jdk8/PlatformThreadLocalRandom.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package kotlin.random.jdk8 + +import java.util.concurrent.ThreadLocalRandom + +@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "CANNOT_OVERRIDE_INVISIBLE_MEMBER") +internal class PlatformThreadLocalRandom : kotlin.random.AbstractPlatformRandom() { + // TODO no bridge generated for covariant override + override val impl: java.util.Random get() = ThreadLocalRandom.current() + + override fun nextInt(origin: Int, bound: Int): Int = ThreadLocalRandom.current().nextInt(origin, bound) + override fun nextLong(bound: Long): Long = ThreadLocalRandom.current().nextLong(bound) + override fun nextLong(origin: Long, bound: Long): Long = ThreadLocalRandom.current().nextLong(origin, bound) + override fun nextDouble(bound: Double): Double = ThreadLocalRandom.current().nextDouble(bound) + override fun nextDouble(origin: Double, bound: Double): Double = ThreadLocalRandom.current().nextDouble(origin, bound) +} \ No newline at end of file