Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

scala

sbt

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)

like image 873
fullStackRyan Avatar asked Sep 15 '25 13:09

fullStackRyan


2 Answers

The problem is coming from sbt-dotenv.

At the root folder of your project, just create a .jvmopts file containing the following lines:

--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED 
like image 102
Thomas Lehoux Avatar answered Sep 17 '25 04:09

Thomas Lehoux


The stack trace mentions "au.com.onegeek.sbtdotenv", so apparently this is coming from https://github.com/mefellows/sbt-dotenv.

You could try upgrading to the latest version of that plugin and see if the problem goes away.

If it doesn't, you could report the issue to the maintainer.

In that repo's README, there is a section about similar errors: https://github.com/mefellows/sbt-dotenv#illegal-reflective-access-warnings

It isn't clear to me if that's the same or different.

like image 45
Seth Tisue Avatar answered Sep 17 '25 04:09

Seth Tisue