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

1.7.26 regression: NoMethodError: private method `require' called for Kernel:Module in Sequel #4155

Closed
perlun opened this Issue Sep 14, 2016 · 9 comments

Comments

Projects
None yet
4 participants
@perlun
Contributor

perlun commented Sep 14, 2016

Something has gone broken in JRuby 1.7.26, causing the error below.

$ bundle exec irb
The signal IOT is in use by the JVM and will not work correctly on this platform
The signal CLD is in use by the JVM and will not work correctly on this platform
The signal EXIT is in use by the JVM and will not work correctly on this platform
jruby-1.7.26 :001 > require 'sequel'
 => true
jruby-1.7.26 :002 > Sequel.extension :core_extensions
NoMethodError: private method `require' called for Kernel:Module
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/sequel-4.38.0/lib/sequel/core.rb:139:in `extension'
    from org/jruby/RubyArray.java:1613:in `each'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/sequel-4.38.0/lib/sequel/core.rb:139:in `extension'
    from (irb):2:in `evaluate'
    from org/jruby/RubyKernel.java:1079:in `eval'
    from org/jruby/RubyKernel.java:1479:in `loop'
    from org/jruby/RubyKernel.java:1242:in `catch'
    from org/jruby/RubyKernel.java:1242:in `catch'
    from /Users/plundberg/.rvm/rubies/jruby-1.7.26/bin/irb:13:in `(root)'
    from org/jruby/RubyKernel.java:1059:in `load'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/cli/exec.rb:1:in `(root)'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/cli/exec.rb:74:in `kernel_load'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/cli/exec.rb:27:in `run'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/cli.rb:332:in `exec'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/cli.rb:20:in `dispatch'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/cli.rb:11:in `start'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/exe/bundle:34:in `(root)'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors'
    from org/jruby/RubyKernel.java:1059:in `load'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/gems/bundler-1.13.1/exe/bundle:26:in `(root)'
    from org/jruby/RubyKernel.java:1079:in `eval'
    from /Users/plundberg/.rvm/gems/jruby-1.7.26/bin/bundle:1:in `(root)'jruby-1.7.26 :003 > quit

When I switch to JRuby 1.7.25, all is fine:

$ rvm use 1.7.25
Using /Users/plundberg/.rvm/gems/jruby-1.7.25
$ bundle exec irb
jruby-1.7.25 :001 > require 'sequel'
 => true
jruby-1.7.25 :002 > Sequel.extension :core_extensions
 => [:core_extensions]
jruby-1.7.25 :003 > quit

The failing code (https://github.com/jeremyevans/sequel/blob/master/lib/sequel/core.rb#L139) looks like this:

  def self.extension(*extensions)
    extensions.each{|e| Kernel.require "sequel/extensions/#{e}"}
end

Any ideas or suggestions on what change in 1.7.26 could have been causing this?

/cc @olleolleolle, @sdahlbac

@olleolleolle

This comment has been minimized.

Show comment
Hide comment
@olleolleolle

olleolleolle Sep 14, 2016

Contributor

A workaround:

require 'sequel'
module Sequel
  def self.extension(*extensions)
    extensions.each { |e| Kernel.send(:require, "sequel/extensions/#{e}") } # PATCH: avoid Kernel.require being private
  end
end
Sequel.extension :core_extensions
Contributor

olleolleolle commented Sep 14, 2016

A workaround:

require 'sequel'
module Sequel
  def self.extension(*extensions)
    extensions.each { |e| Kernel.send(:require, "sequel/extensions/#{e}") } # PATCH: avoid Kernel.require being private
  end
end
Sequel.extension :core_extensions
@jayjlawrence

This comment has been minimized.

Show comment
Hide comment
@jayjlawrence

jayjlawrence Sep 14, 2016

There is a similar issue with Bundler 1.13 and 1.13.1. The issue is also present in jRuby 1.7.24. I haven't checked other versions. See the referenced issue above.

There is a similar issue with Bundler 1.13 and 1.13.1. The issue is also present in jRuby 1.7.24. I haven't checked other versions. See the referenced issue above.

@olleolleolle

This comment has been minimized.

Show comment
Hide comment
@olleolleolle

olleolleolle Sep 14, 2016

Contributor

@perlun Perhaps your jruby-1.7.25 has bundler v1.12.5 installed?

Contributor

olleolleolle commented Sep 14, 2016

@perlun Perhaps your jruby-1.7.25 has bundler v1.12.5 installed?

@olleolleolle

This comment has been minimized.

Show comment
Hide comment
@olleolleolle

olleolleolle Sep 14, 2016

Contributor

The changed Bundler code here, in the #reverse_rubygems_kernel_mixin method - shown next to its older implementation:
bundler/bundler@c144eb6

Contributor

olleolleolle commented Sep 14, 2016

The changed Bundler code here, in the #reverse_rubygems_kernel_mixin method - shown next to its older implementation:
bundler/bundler@c144eb6

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Sep 14, 2016

Member

This is very strange. Kernel.require appears to be public and callable in all recent JRuby versions I tried.

Member

headius commented Sep 14, 2016

This is very strange. Kernel.require appears to be public and callable in all recent JRuby versions I tried.

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Sep 14, 2016

Member

Ok, so the problem is definitely from #reverse_rubygems_kernel_mixin, which attempts to restore the original require over the top of the patched version from RubyGems. In this case, it yanks gem_original_require out as an unbound method and redefines it as require. It basically transplants the old one back in.

bundler/bundler@c144eb6#diff-f271319d553ee0af23e993e254a92c6cR293

In MRI, that causes visibility to be set to whatever is current for the frame, which is usually public. So the new require is public.

In JRuby, because we associate visibility with the method rather than with the method table entry, the original private visibility sticks to the method object and it remains private after transplanted. So this logic causes require to be private when it was public.

Working with bundler folks on a fix now in bundler/bundler#4975

Member

headius commented Sep 14, 2016

Ok, so the problem is definitely from #reverse_rubygems_kernel_mixin, which attempts to restore the original require over the top of the patched version from RubyGems. In this case, it yanks gem_original_require out as an unbound method and redefines it as require. It basically transplants the old one back in.

bundler/bundler@c144eb6#diff-f271319d553ee0af23e993e254a92c6cR293

In MRI, that causes visibility to be set to whatever is current for the frame, which is usually public. So the new require is public.

In JRuby, because we associate visibility with the method rather than with the method table entry, the original private visibility sticks to the method object and it remains private after transplanted. So this logic causes require to be private when it was public.

Working with bundler folks on a fix now in bundler/bundler#4975

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Sep 14, 2016

Member

We have proposed to bundler that they modify the redefine_method logic to also send(:public, ...) after the transplanting. It will hurt no Ruby and will allow the logic to work on any JRuby version.

FWIW, recent 9k (since 9.1.3.0) does not appear to have this problem. I fixed #3869 in 9b4e97b on master but did not backport that fix to 1.7. All versions of JRuby prior to 1.7.27 and 9.1.3.0 will have this bug.

Member

headius commented Sep 14, 2016

We have proposed to bundler that they modify the redefine_method logic to also send(:public, ...) after the transplanting. It will hurt no Ruby and will allow the logic to work on any JRuby version.

FWIW, recent 9k (since 9.1.3.0) does not appear to have this problem. I fixed #3869 in 9b4e97b on master but did not backport that fix to 1.7. All versions of JRuby prior to 1.7.27 and 9.1.3.0 will have this bug.

headius added a commit that referenced this issue Sep 14, 2016

Stop using WrapperMethod, since it messes up super logic.
This is for #3869 and relates to the module_function change from
and redefine it with a new visibility and implementation class.
However the impl class never passed through to the contained
method, preventing it from being used in super. This affected, for
example, module_fuction singleton methods that need to super or
methods transplanted using defined_method with a Method instance.
The new logic always tries to dup the target method so it can
be truly populated with the altered fields. This change fixed

The previous commit, using cloning instead of construction for
IR methods, works around the fact that there's no semi-transparent
WrapperMethod to delegate its serial number to the wrapped method.
Since in that case and in this one, the method's serial number
was expected to be the same after duplication, the clone
technique seems acceptable.

jruby-1_7: Fixes #4155

@headius headius added this to the JRuby 1.7.27 milestone Sep 14, 2016

headius added a commit that referenced this issue Sep 14, 2016

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Sep 14, 2016

Member

Thanks for the footwork on this one, @olleolleolle and @jayjlawrence, you made it easy to track down.

Member

headius commented Sep 14, 2016

Thanks for the footwork on this one, @olleolleolle and @jayjlawrence, you made it easy to track down.

@headius headius closed this Sep 14, 2016

@perlun

This comment has been minimized.

Show comment
Hide comment
@perlun

perlun Sep 15, 2016

Contributor

Thanks a lot for sorting this out @headius, @olleolleolle & @jayjlawrence - I'm happy to have been wrong this time (it wasn't really a regression in JRuby). Even happier that it has been fixed now. 👍

Contributor

perlun commented Sep 15, 2016

Thanks a lot for sorting this out @headius, @olleolleolle & @jayjlawrence - I'm happy to have been wrong this time (it wasn't really a regression in JRuby). Even happier that it has been fixed now. 👍

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