Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doing require_relative too often leads to TypeError #4482

Closed
janlelis opened this issue Feb 7, 2017 · 4 comments
Closed

Doing require_relative too often leads to TypeError #4482

janlelis opened this issue Feb 7, 2017 · 4 comments

Comments

@janlelis
Copy link

janlelis commented Feb 7, 2017

Environment

  • ruby -v jruby 9.1.8.0-SNAPSHOT (2.3.1) 2017-02-06 3f97c7a Java HotSpot(TM) 64-Bit Server VM 25.111-b14 on 1.8.0_111-b14 +indy +jit [linux-x86_64]
  • uname -a Linux ok 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Setup

Empty file: a.rb

Contents of b.rb, in the same directory:

400.times{
  require_relative 'a'
}

Expected Behavior

  • Should print nothing

Actual Behavior

  • Throws following error:
TypeError: no implicit conversion of nil into String
          realpath at org/jruby/RubyFile.java:862
  require_relative at uri:classloader:/jruby/kernel/kernel.rb:11
  require_relative at uri:classloader:/jruby/kernel/kernel.rb:-1
     block in b.rb at b.rb:2
             times at org/jruby/RubyFixnum.java:299
            <main> at b.rb:1

Works find for a smaller iteration count, for example, 4.

@enebo
Copy link
Member

enebo commented Feb 9, 2017

@janlelis two things. Can you figure out if it always happens at a particular number (e.g. 20)? Also do you have any JRUBY_OPTS set. I am not seeing this but I am using MacOS so perhaps there is a platform difference?

@enebo enebo added this to the JRuby 9.1.8.0 milestone Feb 9, 2017
@janlelis
Copy link
Author

janlelis commented Feb 9, 2017

I forgot about it, indeed, I have JRUBY_OPTS set to -Xcompile.invokedynamic=true and I can verify, without this option, the bug does not occur.

It seems to usually fail between the 50th - 100th call.

I also noticed, after rescueing the TypeError, subsequent calls to require_relative will not trigger the error again.

With this test script as b.rb:

begin
  i = 0
  while i < 100_000
    i += 1
    require_relative "a"
  end
  puts "No errors"
rescue
  puts "#{i} | #{$!}"
end

I get the following output for number in {1..10} ; do ruby b.rb ; done:

82 | no implicit conversion of nil into String
72 | no implicit conversion of nil into String
70 | no implicit conversion of nil into String
58 | no implicit conversion of nil into String
71 | no implicit conversion of nil into String
79 | no implicit conversion of nil into String
82 | no implicit conversion of nil into String
60 | no implicit conversion of nil into String
84 | no implicit conversion of nil into String
79 | no implicit conversion of nil into String

@headius
Copy link
Member

headius commented Feb 9, 2017

Definitely a JIT+indy bug. I have no clue at the moment.

@ghost
Copy link

ghost commented Feb 14, 2017

Can confirm.

Had an old hackish script to load all dependent source files from a sub-directory (about 120 of them) using the following code. It would error at seemingly random points in the execution, sometimes failing a little before halfway, sometimes failing right before the end. There does not seem to be a pattern to it.

It was definitely running with +indy.

Example Code

# invoked from project root, so use .. to coerce back into real path
Dir.glob('subfolder/*.rb').each {|file| require_relative("../#{file}") }

I do not recall if adding a rescue nil after the require_relative alleviated the TypeError or not (but if so, would have surely broken a dependency).

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

No branches or pull requests

3 participants