Subtle differences in System.getenv() between Windows and Linux
Galder Zamarreno
galder at redhat.com
Tue Mar 9 12:15:21 UTC 2021
Hi all,
One of my colleagues discovered an intriguing difference between Linux and
Windows, in the context of GraalVM native-image, when it comes to the
returned value for System.getenv().
On windows, the native test he's encountered that a test fails with:
> Error: No instances of java.lang.ProcessEnvironment are allowed in the
image heap as this class should be initialized at image runtime
This does not happen on Linux.
The reason it fails on Windows it's because on that env the System.getenv()
method returns a ProcessEnvironment type, which happens to extend HashMap
[1]. On linux though it returns a plain map [2].
Any reason for this divergence? Is it due to historic reasons? I wondered
whether the windows and linux version of this shouldn't be more akin.
Galder
[1]
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/windows/classes/java/lang/ProcessEnvironment.java#L69
[2]
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/unix/classes/java/lang/ProcessEnvironment.java#L90
More information about the core-libs-dev
mailing list