Hi,
The code in both versions of ProcessEnvironment is mostly pre-2007
seem to have the same original author.
It is the typical inheritance vs delegation choice and likely driven by
the details
of what was being stored and the OS specific details that need to be
processed.
For example, Linux is case-sensitive vs Windows case-insensitive
and the handling needed to read the environment from the OS and
generate the environment for process launch.
$.02, Roger
On 3/9/21 7:15 AM, Galder Zamarreno wrote:
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