diff --git a/libraries/stdlib/src/kotlin/internal/PlatformImplementations.kt b/libraries/stdlib/src/kotlin/internal/PlatformImplementations.kt index 158eb814e92..adbfb6faf34 100644 --- a/libraries/stdlib/src/kotlin/internal/PlatformImplementations.kt +++ b/libraries/stdlib/src/kotlin/internal/PlatformImplementations.kt @@ -20,44 +20,42 @@ internal open class PlatformImplementations { public open fun getMatchResultNamedGroup(matchResult: MatchResult, name: String): MatchGroup? { throw UnsupportedOperationException("Retrieving groups by name is not supported on this platform.") } - - companion object { - @JvmField - @InlineExposed - val INSTANCE: PlatformImplementations = run { - val version = getJavaVersion() - try { - if (version >= 0x10008) - return@run Class.forName("kotlin.internal.JDK8PlatformImplementations").newInstance() as PlatformImplementations - } catch (e: ClassNotFoundException) {} - - try { - if (version >= 0x10007) - return@run Class.forName("kotlin.internal.JDK7PlatformImplementations").newInstance() as PlatformImplementations - } catch (e: ClassNotFoundException) {} - - PlatformImplementations() - } - - private fun getJavaVersion(): Int { - val default = 0x10006 - val version = System.getProperty("java.version") ?: return default - val firstDot = version.indexOf('.') - if (firstDot < 0) return default - var secondDot = version.indexOf('.', firstDot + 1) - if (secondDot < 0) secondDot = version.length - - val firstPart = version.substring(0, firstDot) - val secondPart = version.substring(firstDot + 1, secondDot) - return try { - firstPart.toInt() * 0x10000 + secondPart.toInt() - } catch (e: NumberFormatException) { - default - } - } - - } - - +} + +@kotlin.internal.InlineExposed +internal fun platformCloseSuppressed(instance: Closeable, cause: Throwable) = IMPLEMENTATIONS.closeSuppressed(instance, cause) + + +@JvmField +internal val IMPLEMENTATIONS: PlatformImplementations = run { + val version = getJavaVersion() + try { + if (version >= 0x10008) + return@run Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance() as PlatformImplementations + } catch (e: ClassNotFoundException) {} + + try { + if (version >= 0x10007) + return@run Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance() as PlatformImplementations + } catch (e: ClassNotFoundException) {} + + PlatformImplementations() +} + +private fun getJavaVersion(): Int { + val default = 0x10006 + val version = System.getProperty("java.version") ?: return default + val firstDot = version.indexOf('.') + if (firstDot < 0) return default + var secondDot = version.indexOf('.', firstDot + 1) + if (secondDot < 0) secondDot = version.length + + val firstPart = version.substring(0, firstDot) + val secondPart = version.substring(firstDot + 1, secondDot) + return try { + firstPart.toInt() * 0x10000 + secondPart.toInt() + } catch (e: NumberFormatException) { + default + } } diff --git a/libraries/stdlib/src/kotlin/io/ReadWrite.kt b/libraries/stdlib/src/kotlin/io/ReadWrite.kt index a8948c7dbe9..c0fec9c66f6 100644 --- a/libraries/stdlib/src/kotlin/io/ReadWrite.kt +++ b/libraries/stdlib/src/kotlin/io/ReadWrite.kt @@ -6,7 +6,7 @@ import java.io.* import java.nio.charset.Charset import java.net.URL import java.util.NoSuchElementException -import kotlin.internal.PlatformImplementations +import kotlin.internal.* /** Returns a buffered reader wrapping this Reader, or this Reader itself if it is already buffered. */ @@ -159,7 +159,7 @@ public inline fun T.use(block: (T) -> R): R { } catch (e: Throwable) { closed = true @Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE") - PlatformImplementations.INSTANCE.closeSuppressed(this, e) + platformCloseSuppressed(this, e) throw e } finally { if (!closed) { diff --git a/libraries/stdlib/src/kotlin/text/regex/Regex.kt b/libraries/stdlib/src/kotlin/text/regex/Regex.kt index cc8f7031c83..4391b2d5fa8 100644 --- a/libraries/stdlib/src/kotlin/text/regex/Regex.kt +++ b/libraries/stdlib/src/kotlin/text/regex/Regex.kt @@ -19,7 +19,7 @@ package kotlin.text import java.util.* import java.util.regex.Matcher import java.util.regex.Pattern -import kotlin.internal.DefaultPlatformImplementations +import kotlin.internal.IMPLEMENTATIONS private interface FlagEnum { public val value: Int @@ -247,7 +247,7 @@ private class MatcherMatchResult(private val matcher: Matcher, private val input null } override fun get(name: String): MatchGroup? { - return DefaultPlatformImplementations.INSTANCE.getMatchResultNamedGroup(matchResult, name) + return IMPLEMENTATIONS.getMatchResultNamedGroup(matchResult, name) } } diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt index e4f31d17275..a730c79df5b 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt @@ -1583,6 +1583,10 @@ public final class kotlin/concurrent/TimersKt { public static final fun timer (Ljava/lang/String;Z)Ljava/util/Timer; } +public final class kotlin/internal/PlatformImplementationsKt { + public static final fun platformCloseSuppressed (Ljava/io/Closeable;Ljava/lang/Throwable;)V +} + public final class kotlin/io/AccessDeniedException : kotlin/io/FileSystemException { public fun (Ljava/io/File;Ljava/io/File;Ljava/lang/String;)V public synthetic fun (Ljava/io/File;Ljava/io/File;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -2082,6 +2086,10 @@ public abstract interface class kotlin/text/MatchGroupCollection : java/util/Col public abstract fun get (I)Lkotlin/text/MatchGroup; } +public abstract interface class kotlin/text/MatchNamedGroupCollection : kotlin/text/MatchGroupCollection { + public abstract fun get (Ljava/lang/String;)Lkotlin/text/MatchGroup; +} + public abstract interface class kotlin/text/MatchResult { public abstract fun getDestructured ()Lkotlin/text/MatchResult$Destructured; public abstract fun getGroupValues ()Ljava/util/List;