This project is archived and is in readonly mode.

#5420 ✓committed
Nick Sieger

AD::Routing::Mapper#apply_common_behavior_for: Hash modification during iteration

Reported by Nick Sieger | August 20th, 2010 @ 09:56 PM

The following code fails on JRuby and is bad style and unreliable in general:

options.each do |k,v|
  (options[:constraints] ||= {})[k] = options.delete(k) if options[k].is_a?(Regexp)
end

The failure is as shown in JRuby's CI build:

http://ci.jruby.org/view/Rails/job/rails-master-actionpack-jruby/23...

/Users/nicksieger/Projects/ruby/rails/actionpack/lib/action_dispatch/routing/mapper.rb:778:in `apply_common_behavior_for': can't add a new key into hash during iteration (RuntimeError)
    from /Users/nicksieger/Projects/ruby/rails/actionpack/lib/action_dispatch/routing/mapper.rb:777:in `each'
    from /Users/nicksieger/Projects/ruby/rails/actionpack/lib/action_dispatch/routing/mapper.rb:777:in `apply_common_behavior_for'
    from /Users/nicksieger/Projects/ruby/rails/actionpack/lib/action_dispatch/routing/mapper.rb:602:in `resources'
    from ./test/dispatch/routing_test.rb:229
    from /Users/nicksieger/Projects/ruby/rails/actionpack/lib/action_dispatch/routing/mapper.rb:357:in `scope'
    from ./test/dispatch/routing_test.rb:228
    from /Users/nicksieger/Projects/ruby/rails/actionpack/lib/action_dispatch/routing/mapper.rb:376:in `namespace'
    from /Users/nicksieger/Projects/ruby/rails/actionpack/lib/action_dispatch/routing/mapper.rb:357:in `scope'
     ... 14 levels...
    from /Users/nicksieger/.rvm/gems/jruby-head@rails-test/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
    from /Users/nicksieger/.rvm/gems/jruby-head@rails-test/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
    from /Users/nicksieger/.rvm/gems/jruby-head@rails-test/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5

Patch attached.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Tags

Referenced by

Pages