How to resolve error of java.lang.reflect.InaccessibleObjectException: Unable to make field private static final java.lang.ProcessEnivironment java.lang.ProcessEnvironment.theEnvironment accessible: module java.lang.base does not “opens java.lang” to unnamed module

Hi Folks,

In this short post we talk about how to work around an error I got when trying to build a Kotlin project. The error looks like:

java.lang.reflect.InaccessibleObjectException: Unable to make field private static final java.lang.ProcessEnivironment java.lang.ProcessEnvironment.theEnvironment  accessible: module java.lang.base does not “opens java.lang” to unnamed module

After some research, I found a way to build the project. The workaround is as follows:

  • Click to Edit Configurations…
  • Find the current build configuration
  • Paste the following under VM options.
--add-opens java.base/java.lang=ALL-UNAMED --add-opens java.base/java.nio=ALL-UNAMED --add-opens java.base/sun.nio.ch=ALL-UNAMED
  • Click Apply
  • Close the configurations dialog.

That’s it. Your build should now work. That’s all for now. Till next time, happy software development.