Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `[]' on nil:NilClass. #2826

Open
funal125 opened this Issue Dec 12, 2013 · 5 comments

Comments

Projects
None yet
4 participants

I have done some test, and found a strange error. Here is my code

[25] pry(main)> a = "11111"
=> "11111"
[26] pry(main)> a.size.times { |i| a[i] }
=> 5

It looks ok,

[37] pry(main)> 10_000.times { a.size.times { |i| a[i] } }
=> 10000

It also looks ok,but

[38] pry(main)> 100_000.times { a.size.times { |i| a[i] } }
NoMethodError: undefined method []' on nil:NilClass. from kernel/delta/kernel.rb:78:in'

what happened?

I don't know how to figure it out.

@funal125 funal125 closed this Dec 21, 2013

Owner

dbussink commented Dec 21, 2013

If this is a reproducible problem we should nt close it so we won't just leave this bug in there. Even if we don't know / have a solution immediately.

@dbussink dbussink reopened this Dec 21, 2013

It's very strange, i tested it in irb. Sometimes it works, and some time it fails. I really don't know how to trace the issue.

Got similar error with rbx-2.2.6 on OS X in IRB.
Works fine if saved to file and executed as ruby issue.rb.

Tried to intercept error (begin/rescue, debugger) but all the involved objects are not nil.

haystack = []
1000.times do |i|
  haystack << {:a => i, :b => i+1, :c => i+2}
end

needle = {:a => 300, :b => 301}

n = 50000

n.times do |n|
  haystack.any? {|haystack_item|
    haystack_item.select {|k,v| needle.keys.include?( k ) } == needle
  }
end
NoMethodError: undefined method `keys' on nil:NilClass.
  from kernel/delta/kernel.rb:78:in `keys (method_missing)'
  from (irb):12:in `__block__'
  from kernel/common/hash.rb:517:in `select'
  from kernel/common/hash.rb:326:in `each_item'
  from kernel/common/hash.rb:514:in `select'
  from (irb):12
  from kernel/common/enumerable.rb:313:in `any?'
  from kernel/bootstrap/array.rb:66:in `each'
  from kernel/common/enumerable.rb:313:in `any?'
  from (irb):11
  from kernel/common/integer.rb:198:in `times'
  from (irb):10
  from kernel/common/block_environment.rb:53:in `call_on_instance'
  from kernel/common/eval.rb:176:in `eval'
  from kernel/common/kernel.rb:460:in `loop'
  from kernel/bootstrap/proc.rb:20:in `call'
... 1 levels...
  from kernel/common/throw_catch.rb:8:in `register'
  from kernel/common/throw_catch.rb:29:in `catch'
  from kernel/bootstrap/proc.rb:20:in `call'
  from kernel/common/throw_catch.rb:30:in `catch'
  from kernel/common/throw_catch.rb:8:in `register'
  from kernel/common/throw_catch.rb:29:in `catch'
  from /Users/eisenhorn/.rvm/gems/rbx-2.2.6@global/gems/rubysl-irb-2.0.4/bin/irb:12:in `__script__'
  from kernel/common/kernel.rb:447:in `load'
  from /Users/eisenhorn/.rvm/gems/rbx-2.2.6@global/bin/irb:23:in `__script__'
  from kernel/common/block_environment.rb:53:in `call_on_instance'
  from kernel/common/eval.rb:176:in `eval'
  from /Users/eisenhorn/.rvm/gems/rbx-2.2.6@global/bin/ruby_executable_hooks:15:in `__script__'
  from kernel/delta/code_loader.rb:66:in `load_script'
  from kernel/delta/code_loader.rb:152:in `load_script'
  from kernel/loader.rb:649:in `script'
  from kernel/loader.rb:831:in `main'
Owner

YorickPeterse commented Feb 18, 2015

This still produces said error:

a = "11111"
100_000.times { a.size.times { |i| a[i] } }

One-liner:

rbx -e 'a = "11111"; 100_000.times { a.size.times { |i| a[i] } }'

This doesn't occur when disabling the JIT.

@YorickPeterse YorickPeterse added the JIT label Feb 18, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment