Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: JRuby 1.4
-
Fix Version/s: JRuby 1.5
-
Component/s: Core Classes/Modules, Ruby 1.8.7
-
Labels:None
-
Environment:MRI 1.8.7p174 (compiled by hand on Ubuntu)
MRI 1.8.6p287 (system package on OS X 10.5)
JRuby 1.4.0 (from macports on OS X 10.5)
-
Number of attachments :
Description
Hash#each_pair behaves differently when you add new keys to the hash during iteration on JRuby 1.4.0 and MRI 1.8.7p174. This gist contains a short script which illustrates the different behaviors:
JRuby 1.4.0's behavior is the same as Ruby 1.9.0, not 1.8.7.
I don't know how important this difference is – the 1.8 line's behavior is inconsistent (it seems to be dependent on the iteration order of the pairs), so it would be tricky to be deliberately depending on it. On the other hand, we did run into it in production code: a colleague of mine noticed the problem when executing a method which recursively converted all the keys in a hash to symbols (in place). On MRI 1.8.x, this method would complete, but not on JRuby 1.4.0. (It was trivial to convert this method to a form that would work in both places.)
I attempted to write a RubySpec for this, but since the 1.8 behavior doesn't seem deliberately designed, I wasn't sure how to go about it. I will update this ticket if I make any progress.
My understanding is that in 1.8 the hash insertion order was not specified and JRuby's behavior was intentional.
In 1.9, the order is specified and JRuby and MR 1.9 behave the same.
So it seems that this should be closed as won't fix, or, better, not a bug.