question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SystemEnvironmentTestListener - Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible:

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
Kantiscommented, Jul 1, 2022

I added info here on how you can work around it: https://kotest.io/docs/extensions/system_extensions.html (see the blue info box)

0reactions
jmfayardcommented, Sep 21, 2022

@sksamuel I first raised #3112 which brought me here.

So I edited gradle.properties

-org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx4608M
+org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx4608M --add-opens=java.base/java.util=ALL-UNNAMED

I had a first issue Overriding a variable when mode is set to SetOrError. Use another OverrideMode to allow this. Trying to set {FIXED_OTP=hi42}

That’s not a bug per se, but the fix was not obvious, it would be nice to mention it in the documentation https://kotest.io/docs/extensions/system_extensions.html

-withEnvironment(OtpSource.FIXED_OTP, "hi42", , OverrideMode.SetOrOverride) {
+withEnvironment(OtpSource.FIXED_OTP, "hi42") {
         //
}

Alas that still fails

java.lang.reflect.InaccessibleObjectException: 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 @47089e5f

https://scans.gradle.com/s/rqvdpgm2f5fq6/tests/:test/com.tignum.backend.core.health.SanityCheckerTest/fixed OneTimePassword can be enabled only in the local environment()?expanded-stacktrace=WyIwIl0&top-execution=1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to make field private final java.util ... - Stack Overflow
I solved my problem. Turns out the JRE that eclipse had automatically downloaded and was using wasn't compatible with this version of ...
Read more >
Fix 'Unable make field private final java.util ... - YouTube
Cucumber #Selenium #Appium #RestAssured #Automation#Error message #ExceptionInInitializerError # java. util.
Read more >
Example usage for java.lang.reflect Field setAccessible
In this page you can find the example usage for java.lang.reflect Field ... setAccessible(true); Object obj = field.get(env); Map<String, String> map ...
Read more >
Java 16 error in "HTreeMap.put()": Unable to make field final java.util ...
Hi,. I switched to Java 16 today, and the put() below produces an error. It works with Java 15. My code is compiled...
Read more >
unable to make field private final java.time ... - You.com
LocalDate java.time.LocalDateTime.date accessible: module java.base does not "opens java.time" to unnamed module @27abe2cd'} java.lang.reflect ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found