Unable to make field private static final java.util.HashMap java.lang.ProcessEnvironment.theEnvironment accessible

Viewed 1452

When I run sbt, I get the below. I am still able to keep working but the warning/error annoys me and clutters my terminal. Any idea how I resolve this?

java.lang.reflect.InaccessibleObjectException: Unable to make field private static final java.util.HashMap java.lang.ProcessEnvironment.theEnvironment accessible: module java.base does not "opens java.lang" to unnamed module @43016
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
        at au.com.onegeek.sbtdotenv.DirtyEnvironmentHack$.$anonfun$setEnv$1(DirtyEnvironmentHack.scala:42)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at scala.util.Try$.apply(Try.scala:213)
        at au.com.onegeek.sbtdotenv.DirtyEnvironmentHack$.setEnv(DirtyEnvironmentHack.scala:38)
        at au.com.onegeek.sbtdotenv.SbtDotenv$.configureEnvironment(SbtDotenv.scala:71)
        at au.com.onegeek.sbtdotenv.SbtDotenv$autoImport$.$anonfun$dotEnv$1(SbtDotenv.scala:42)
        at scala.Function1.$anonfun$compose$1(Function1.scala:49)
        at scala.Function1.$anonfun$compose$1(Function1.scala:49)
        at scala.Function1.$anonfun$compose$1(Function1.scala:49)
        at scala.Function1.$anonfun$compose$1(Function1.scala:49)
        at scala.Function1.$anonfun$compose$1(Function1.scala:49)
        at scala.Function1.$anonfun$compose$1(Function1.scala:49)
        at scala.Function1.$anonfun$compose$1(Function1.scala:49)
        at sbt.Project$.setProject(Project.scala:501)

2 Answers

Assuming sbt-dotenv is the culprit, you can try a couple of things:

  1. Create a .jvmopts and place it at the root folder of your project.
  2. Prefix the export keyword in your .env variables.

This should solve the issue

Related