ENV needs to be a true proxy to getenv rather than a Hashย #3924
Description
Environment
JRuby, all versions.
Expected Behavior
In MRI, ENV is not a Hash but a pseudo-Hash-like singleton object with all of its own methods. This is done so that all Hash-y operations actually go directly to and from the system environment via getenv and setenv.
Actual Behavior
In JRuby, we have the following differences:
- ENV is a subclass of Hash
- ENV overrides a few Hash methods to handle case-insensitivity, ArgumentError: string contains null byteย #3907 PATH encoding, and so on.
- ENV is populated at boot by first creating a Map of RubyString, and then by inserting that Map's contents into ENV itself.
This allows us to delegate some of ENV's logic to Hash, but also results in a lot of needless complexity and a visible difference from MRI.
In the case of ENV_JAVA, we do basically the same process, when we really could just go directly to/from System.getProperty/setProperty.
I propose that we fix this in a 9k release by making ENV truly just be a proxy as in MRI.
There is one possible side effect of following MRI's course: We would not cache the Ruby String instances that ENV produces, and would have to transcode to/from Java String to interact with env and property APIs.