Getting a live view of environment variables (Gradle and JDK 9)

Stephen Colebourne scolebourne at joda.org
Thu May 18 08:35:23 UTC 2017


On 18 May 2017 at 09:07, David Holmes <david.holmes at oracle.com> wrote:
> I'm quite surprised by some of the reactions here. Given the read-once
> nature of System.getenv was never documented I expected most people to be
> surprised that it took a snapshot-on-first-use, and that reading the actual
> process environment at the time System.getenv was called would be the
> natural expectation as to how this API works.

I agree with Daivid that my expectation for the method System.getenv
would be that it calls native code every time it is invoked assuming
that the Javadoc didn't say otherwise (because environment variables
are outside the Java universe). As such, the choice to snapshot looks
like a significant change in behaviour, and thus compatibility.

I also note the method getenv() - the one that returns a Map. It has
the Javadoc "Returns an unmodifiable string map view of the current
system environment". Note the word "current". I take that to imply
*now*. Again, this change seems incompatible. At the very least, the
specification is now wrong.

Stephen


More information about the core-libs-dev mailing list