kotest: SystemEnvironmentTestListener - Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible:
Which version of Kotest are you using KoTest - 5.3
Kotlin - 1.6.20
I’m getting the following error when trying to run this code line in a WordSpec test.
class PublisherServiceTest : WordSpec() {
private val pubSubService = install(TestContainerExtension(pubSubContainer)) {
addExposedPort(8085)
}
private val address: String = "${pubSubService.host}:${pubSubService.firstMappedPort}"
override fun listeners() = listOf(SystemEnvironmentTestListener("PUBSUB_TARGET", address)) //<<< FAILING HERE
init {
...
}
}
Error Message:
Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module @309e345f
This is directly thrown when in SystemEnviromentExtensions.kt line 99 is called:
classOfMap.getDeclaredField("m").asAccessible().get(systemEnv) as MutableMap<String, String>
method: getEditableMapOfVariables
@Suppress("UNCHECKED_CAST")
private fun getEditableMapOfVariables(): MutableMap<String, String> {
val systemEnv = System.getenv()
val classOfMap = systemEnv::class.java
return classOfMap.getDeclaredField("m").asAccessible().get(systemEnv) as MutableMap<String, String>
}
Is there something I’m doing wrong?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (12 by maintainers)
Commits related to this issue
- Gradle: Allow Kotest's `withEnvironment()` to work with Java 17 For more background information see [1]. [1]: https://github.com/kotest/kotest/issues/3035 Co-authored-by: Martin Nonnenmacher <marti... — committed to oss-review-toolkit/ort by sschuberth 2 years ago
- Gradle: Allow Kotest's `withEnvironment()` to work with Java 17 For more background information see [1]. [1]: https://github.com/kotest/kotest/issues/3035 Co-authored-by: Martin Nonnenmacher <marti... — committed to oss-review-toolkit/ort by sschuberth 2 years ago
- Gradle: Allow Kotest's `withEnvironment()` to work with Java 17 For more background information see [1]. [1]: https://github.com/kotest/kotest/issues/3035 Co-authored-by: Martin Nonnenmacher <marti... — committed to oss-review-toolkit/ort by sschuberth 2 years ago
- Test compatibility with JVM 17 See https://github.com/kotest/kotest/issues/3035 — committed to GEO-BON/bon-in-a-box-pipelines by jmlord a year ago
- Test compatibility with JVM 17 See https://github.com/kotest/kotest/issues/3035 — committed to GEO-BON/bon-in-a-box-pipeline-engine by jmlord a year ago
- Test compatibility with JVM 17 See https://github.com/kotest/kotest/issues/3035 — committed to GEO-BON/bon-in-a-box-pipeline-engine by jmlord a year ago
For me, the only fix was to have the following in the
build.gradle.kts:Adding the arguments to
gradle.propertiesdid not help.I added info here on how you can work around it: https://kotest.io/docs/extensions/system_extensions.html (see the blue info box)