Skip to content

Commit 2cafea4

Browse files
authored
Update Kotlin to 2.1.0 (#4284)
* Bump Kotlin version to 2.1 * Warnings cleanup * Update Kotlin version in integration tests * Upgrade Gradle in integration tests * Fix classloading test after more precise Gradle classpath resolution
1 parent 9f6c80b commit 2cafea4

31 files changed

+93
-60
lines changed

gradle.properties

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Kotlin
22
version=1.9.0-SNAPSHOT
33
group=org.jetbrains.kotlinx
4-
kotlin_version=2.0.0
5-
kotlin_language_version=2.0
4+
kotlin_version=2.1.0
5+
kotlin_language_version=2.1
66
# DO NOT rename this property without adapting kotlinx.train build chain:
77
atomicfu_version=0.26.1
88

@@ -43,7 +43,6 @@ kotlin.native.ignoreDisabledTargets=true
4343
# TODO: Remove once KT-37187 is fixed
4444
org.gradle.jvmargs=-Xmx3g
4545

46-
kotlin.mpp.stability.nowarn=true
4746
kotlinx.atomicfu.enableJvmIrTransformation=true
4847
# When the flag below is set to `true`, AtomicFU cannot process
4948
# usages of `moveForward` in `ConcurrentLinkedList.kt` correctly.

integration-testing/build.gradle

+10-2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ sourceSets {
122122
compileDebugAgentTestKotlin {
123123
kotlinOptions {
124124
freeCompilerArgs += ["-Xallow-kotlin-package"]
125+
jvmTarget = "1.8"
125126
}
126127
}
127128

@@ -163,19 +164,26 @@ task coreAgentTest(type: Test) {
163164
}
164165

165166
compileTestKotlin {
166-
kotlinOptions.jvmTarget = "1.8"
167+
kotlinOptions.jvmTarget = "17"
167168
}
168169

169170
check {
170171
dependsOn([jvmCoreTest, debugDynamicAgentTest, mavenTest, debugAgentTest, coreAgentTest, ":jpmsTest:check", 'smokeTest:build', "java8Test:check"])
171172
}
173+
172174
compileKotlin {
173175
kotlinOptions {
174-
jvmTarget = "1.8"
176+
jvmTarget = "17"
175177
}
176178
}
177179

180+
kotlin.jvmToolchain(17)
181+
178182
// Drop this when node js version become stable
179183
tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask.class).configureEach {
180184
it.args.add("--ignore-engines")
181185
}
186+
187+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile.class).configureEach {
188+
jvmTargetValidationMode = org.jetbrains.kotlin.gradle.dsl.jvm.JvmTargetValidationMode.WARNING
189+
}

integration-testing/gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
kotlin_version=2.0.0
1+
kotlin_version=2.1.0
22
coroutines_version=1.9.0-SNAPSHOT
33
asm_version=9.3
44
junit5_version=5.7.0
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
46
zipStoreBase=GRADLE_USER_HOME
57
zipStorePath=wrapper/dists

integration-testing/gradlew

+31-13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
1820

1921
##############################################################################
2022
#
@@ -55,7 +57,7 @@
5557
# Darwin, MinGW, and NonStop.
5658
#
5759
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
60+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5961
# within the Gradle project.
6062
#
6163
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +82,12 @@ do
8082
esac
8183
done
8284

83-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84-
85-
APP_NAME="Gradle"
85+
# This is normally unused
86+
# shellcheck disable=SC2034
8687
APP_BASE_NAME=${0##*/}
87-
88-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
88+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90+
' "$PWD" ) || exit
9091

9192
# Use the maximum available, or set MAX_FD != -1 to use that value.
9293
MAX_FD=maximum
@@ -133,22 +134,29 @@ location of your Java installation."
133134
fi
134135
else
135136
JAVACMD=java
136-
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137+
if ! command -v java >/dev/null 2>&1
138+
then
139+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137140
138141
Please set the JAVA_HOME variable in your environment to match the
139142
location of your Java installation."
143+
fi
140144
fi
141145

142146
# Increase the maximum file descriptors if we can.
143147
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144148
case $MAX_FD in #(
145149
max*)
150+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
151+
# shellcheck disable=SC2039,SC3045
146152
MAX_FD=$( ulimit -H -n ) ||
147153
warn "Could not query maximum file descriptor limit"
148154
esac
149155
case $MAX_FD in #(
150156
'' | soft) :;; #(
151157
*)
158+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
159+
# shellcheck disable=SC2039,SC3045
152160
ulimit -n "$MAX_FD" ||
153161
warn "Could not set maximum file descriptor limit to $MAX_FD"
154162
esac
@@ -193,18 +201,28 @@ if "$cygwin" || "$msys" ; then
193201
done
194202
fi
195203

196-
# Collect all arguments for the java command;
197-
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198-
# shell script including quotes and variable substitutions, so put them in
199-
# double quotes to make sure that they get re-expanded; and
200-
# * put everything else in single quotes, so that it's not re-expanded.
204+
205+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
206+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
207+
208+
# Collect all arguments for the java command:
209+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
210+
# and any embedded shellness will be escaped.
211+
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
212+
# treated as '${Hostname}' itself on the command line.
201213

202214
set -- \
203215
"-Dorg.gradle.appname=$APP_BASE_NAME" \
204216
-classpath "$CLASSPATH" \
205217
org.gradle.wrapper.GradleWrapperMain \
206218
"$@"
207219

220+
# Stop when "xargs" is not available.
221+
if ! command -v xargs >/dev/null 2>&1
222+
then
223+
die "xargs is not available"
224+
fi
225+
208226
# Use "xargs" to parse quoted args.
209227
#
210228
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

integration-testing/gradlew.bat

+21-16
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
@rem See the License for the specific language governing permissions and
1414
@rem limitations under the License.
1515
@rem
16+
@rem SPDX-License-Identifier: Apache-2.0
17+
@rem
1618

17-
@if "%DEBUG%" == "" @echo off
19+
@if "%DEBUG%"=="" @echo off
1820
@rem ##########################################################################
1921
@rem
2022
@rem Gradle startup script for Windows
@@ -25,7 +27,8 @@
2527
if "%OS%"=="Windows_NT" setlocal
2628

2729
set DIRNAME=%~dp0
28-
if "%DIRNAME%" == "" set DIRNAME=.
30+
if "%DIRNAME%"=="" set DIRNAME=.
31+
@rem This is normally unused
2932
set APP_BASE_NAME=%~n0
3033
set APP_HOME=%DIRNAME%
3134

@@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4043

4144
set JAVA_EXE=java.exe
4245
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
46+
if %ERRORLEVEL% equ 0 goto execute
4447

45-
echo.
46-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47-
echo.
48-
echo Please set the JAVA_HOME variable in your environment to match the
49-
echo location of your Java installation.
48+
echo. 1>&2
49+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50+
echo. 1>&2
51+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52+
echo location of your Java installation. 1>&2
5053

5154
goto fail
5255

@@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5659

5760
if exist "%JAVA_EXE%" goto execute
5861

59-
echo.
60-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61-
echo.
62-
echo Please set the JAVA_HOME variable in your environment to match the
63-
echo location of your Java installation.
62+
echo. 1>&2
63+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64+
echo. 1>&2
65+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66+
echo location of your Java installation. 1>&2
6467

6568
goto fail
6669

@@ -75,13 +78,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7578

7679
:end
7780
@rem End local scope for the variables with windows NT shell
78-
if "%ERRORLEVEL%"=="0" goto mainEnd
81+
if %ERRORLEVEL% equ 0 goto mainEnd
7982

8083
:fail
8184
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
8285
rem the _cmd.exe /c_ return code!
83-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84-
exit /b 1
86+
set EXIT_CODE=%ERRORLEVEL%
87+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
88+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89+
exit /b %EXIT_CODE%
8590

8691
:mainEnd
8792
if "%OS%"=="Windows_NT" endlocal

integration-testing/src/debugAgentTest/kotlin/DebugAgentTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:OptIn(ExperimentalCoroutinesApi::class)
2+
13
import org.junit.*
24
import kotlinx.coroutines.*
35
import kotlinx.coroutines.debug.*

integration-testing/src/jvmCoreTest/kotlin/ListAllCoroutineThrowableSubclassesTest.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ class ListAllCoroutineThrowableSubclassesTest {
3131
"kotlinx.coroutines.channels.ClosedReceiveChannelException",
3232
"kotlinx.coroutines.flow.internal.ChildCancelledException",
3333
"kotlinx.coroutines.flow.internal.AbortFlowException",
34+
"kotlinx.coroutines.debug.junit5.CoroutinesTimeoutException",
3435
)
3536

3637
@Test
3738
fun testThrowableSubclassesAreSerializable() {
3839
val classes = ClassPath.from(this.javaClass.classLoader)
39-
.getTopLevelClassesRecursive("kotlinx.coroutines");
40+
.getTopLevelClassesRecursive("kotlinx.coroutines")
41+
// Not in the classpath: requires explicit dependency
42+
.filter { it.name != "kotlinx.coroutines.debug.CoroutinesBlockHoundIntegration"
43+
&& it.name != "kotlinx.coroutines.debug.junit5.CoroutinesTimeoutExtension" };
4044
val throwables = classes.filter { Throwable::class.java.isAssignableFrom(it.load()) }.map { it.toString() }
4145
for (throwable in throwables) {
4246
for (field in throwable.javaClass.declaredFields) {

integration-testing/src/mavenTest/kotlin/MavenPublicationMetaInfValidator.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class MavenPublicationMetaInfValidator {
4848
private fun JarFile.checkMetaInfStructure(expected: Set<String>) {
4949
val actual = HashSet<String>()
5050
for (e in entries()) {
51-
if (e.isDirectory() || !e.realName.contains("META-INF")) {
51+
if (e.isDirectory() || !e.name.contains("META-INF")) {
5252
continue
5353
}
54-
val partialName = e.realName.substringAfter("META-INF/")
54+
val partialName = e.name.substringAfter("META-INF/")
5555
actual.add(partialName)
5656
}
5757

kotlinx-coroutines-core/common/src/Builders.common.kt

+3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public suspend fun <T> withContext(
153153
// FAST PATH #1 -- new context is the same as the old one
154154
if (newContext === oldContext) {
155155
val coroutine = ScopeCoroutine(newContext, uCont)
156+
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
156157
return@sc coroutine.startUndispatchedOrReturn(coroutine, block)
157158
}
158159
// FAST PATH #2 -- the new dispatcher is the same as the old one (something else changed)
@@ -161,11 +162,13 @@ public suspend fun <T> withContext(
161162
val coroutine = UndispatchedCoroutine(newContext, uCont)
162163
// There are changes in the context, so this thread needs to be updated
163164
withCoroutineContext(coroutine.context, null) {
165+
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
164166
return@sc coroutine.startUndispatchedOrReturn(coroutine, block)
165167
}
166168
}
167169
// SLOW PATH -- use new dispatcher
168170
val coroutine = DispatchedCoroutine(newContext, uCont)
171+
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
169172
block.startCoroutineCancellable(coroutine, coroutine)
170173
coroutine.getResult()
171174
}

kotlinx-coroutines-core/common/src/CoroutineScope.kt

+1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ public suspend fun <R> coroutineScope(block: suspend CoroutineScope.() -> R): R
281281
}
282282
return suspendCoroutineUninterceptedOrReturn { uCont ->
283283
val coroutine = ScopeCoroutine(uCont.context, uCont)
284+
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
284285
coroutine.startUndispatchedOrReturn(coroutine, block)
285286
}
286287
}

kotlinx-coroutines-core/common/src/Supervisor.kt

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public suspend fun <R> supervisorScope(block: suspend CoroutineScope.() -> R): R
5353
}
5454
return suspendCoroutineUninterceptedOrReturn { uCont ->
5555
val coroutine = SupervisorCoroutine(uCont.context, uCont)
56+
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
5657
coroutine.startUndispatchedOrReturn(coroutine, block)
5758
}
5859
}

kotlinx-coroutines-core/common/src/Timeout.kt

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineSco
4040
}
4141
if (timeMillis <= 0L) throw TimeoutCancellationException("Timed out immediately")
4242
return suspendCoroutineUninterceptedOrReturn { uCont ->
43+
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
4344
setupTimeout(TimeoutCoroutine(timeMillis, uCont), block)
4445
}
4546
}

kotlinx-coroutines-core/common/src/internal/Synchronized.common.kt

+1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ public inline fun <T> synchronized(lock: SynchronizedObject, block: () -> T): T
2424
contract {
2525
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
2626
}
27+
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
2728
return synchronizedImpl(lock, block)
2829
}

kotlinx-coroutines-core/common/test/SupervisorTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
2-
31
package kotlinx.coroutines
42

53
import kotlinx.coroutines.testing.*

kotlinx-coroutines-core/concurrent/src/internal/LockFreeLinkedList.kt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE")
2-
31
package kotlinx.coroutines.internal
42

53
import kotlinx.atomicfu.*
Binary file not shown.

kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt

-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ package kotlinx.coroutines.internal
33
import java.util.*
44
import kotlin.concurrent.withLock as withLockJvm
55

6-
@Suppress("ACTUAL_WITHOUT_EXPECT")
76
internal actual typealias ReentrantLock = java.util.concurrent.locks.ReentrantLock
87

98
internal actual inline fun <T> ReentrantLock.withLock(action: () -> T) = this.withLockJvm(action)
109

11-
@Suppress("ACTUAL_WITHOUT_EXPECT") // Visibility
1210
internal actual typealias WorkaroundAtomicReference<T> = java.util.concurrent.atomic.AtomicReference<T>
1311

1412
// BenignDataRace is OptionalExpectation and doesn't have to be here
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
package kotlinx.coroutines.internal
22

3-
@Suppress("ACTUAL_WITHOUT_EXPECT") // Not the same name to WA the bug in the compiler
43
internal actual typealias IgnoreJreRequirement = org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
package kotlinx.coroutines.internal
22

3-
@Suppress("ACTUAL_WITHOUT_EXPECT")
43
internal actual typealias LocalAtomicInt = java.util.concurrent.atomic.AtomicInteger

kotlinx-coroutines-core/jvm/src/internal/StackTraceRecovery.kt

-2
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,8 @@ private fun StackTraceElement.elementWiseEquals(e: StackTraceElement): Boolean {
198198
&& fileName == e.fileName && className == e.className
199199
}
200200

201-
@Suppress("ACTUAL_WITHOUT_EXPECT")
202201
internal actual typealias CoroutineStackFrame = kotlin.coroutines.jvm.internal.CoroutineStackFrame
203202

204-
@Suppress("ACTUAL_WITHOUT_EXPECT")
205203
internal actual typealias StackTraceElement = java.lang.StackTraceElement
206204

207205
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")

kotlinx-coroutines-core/jvm/src/internal/ThreadLocal.kt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package kotlinx.coroutines.internal
22

33
import java.lang.ThreadLocal
44

5-
@Suppress("ACTUAL_WITHOUT_EXPECT") // internal visibility
65
internal actual typealias CommonThreadLocal<T> = ThreadLocal<T>
76

87
internal actual fun<T> commonThreadLocal(name: Symbol): CommonThreadLocal<T> = ThreadLocal()

0 commit comments

Comments
 (0)