[ruby-core:93151] [Ruby trunk Bug#15920] Check frozen state of ENV

From: merch-redmine@...
Date: 2019-06-15 00:07:47 UTC
List: ruby-core #93151
Issue #15920 has been updated by jeremyevans0 (Jeremy Evans).

File env-no-freeze.patch added

nobu (Nobuyoshi Nakada) wrote:
> I don't think this behavior a bug.
> `ENV` is an interface to the system environment variables, so freezing it doesn't affect the underlying system.

I think the current situation of `ENV.freeze` not raising an exception but still allowing mutation is a bug.  We have two ways to fix it:

* Disallow modifying `ENV` after `ENV.freeze` (my original patch).
* Disallow `ENV.freeze`.  Attached is a another patch that makes `ENV.freeze` raise an exception (I chose `TypeError`).  

> And be careful that an object can never be unfrozen anymore, once it  got frozen.
> For what purpose do you need to prohibit modifying environment variables, and is `ENV.freeze` good for it?

In general, unless you expect to modify the environment, it would be best to freeze it in production applications.  I actually think it is best to freeze as much as possible.  Any object where modification is not required after startup should be frozen as a general principle, in my opinion.  This practice is not yet common in Ruby, though. 

----------------------------------------
Bug #15920: Check frozen state of ENV
https://bugs.ruby-lang.org/issues/15920#change-78587

* Author: kachick (Kenichi Kamiya)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
github: https://github.com/ruby/ruby/pull/2234

Is this an intentional behavior?

``` ruby
ENV.freeze
ENV.clear #=> No exception happen
```

raising FronzenError sounds reasonable to me


---Files--------------------------------
env-frozen.patch (3.9 KB)
env-no-freeze.patch (1.78 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next