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

NullPointerException when trying to assign UnboundMethod using define_method & to_proc #2426

Closed
endofunky opened this issue Jan 5, 2015 · 3 comments

Comments

@endofunky
Copy link

Stumbled upon this earlier when I used define_singleton_method incorrectly.

Code:

class B
  define_singleton_method :new, &Class.instance_method(:new)
end

MRI:

./t.rb:2:in `<class:B>': wrong argument type UnboundMethod (expected Proc) (TypeError)
        from ./t.rb:1:in `<main>'

JRuby:

RubyClass$INVOKER$i$newInstance.gen:-1:in `call': java.lang.NullPointerException
        from RubyMethod.java:194:in `call'
        from CompiledBlock19.java:158:in `yield'
        from CompiledBlock19.java:87:in `call'
        from Block.java:106:in `call'
        from RubyProc.java:301:in `call'
        from ProcMethod.java:64:in `call'
        from DynamicMethod.java:202:in `call'
        from DynamicMethod.java:198:in `call'
        from CachingCallSite.java:297:in `cacheAndCall'
        from CachingCallSite.java:135:in `call'
        from ./t.rb:-1:in `invokeOther2:new'
        from ./t.rb:5:in `__script__'
        from MethodHandle.java:636:in `invokeWithArguments'
        from Compiler.java:112:in `load'
        from Ruby.java:811:in `runScript'
        from Ruby.java:804:in `runScript'
        from Ruby.java:755:in `runNormally'
        from Ruby.java:565:in `runFromMain'
        from Main.java:405:in `doRunFromMain'
        from Main.java:300:in `internalRun'
        from Main.java:227:in `run'
        from Main.java:199:in `main'
@enebo
Copy link
Member

enebo commented Jan 5, 2015

Just a note this is broken on 1.7 and master. The error above is a mild red herring in that the error message we should throw happens in evaluating define_singleton_method and this stack is us trying to execute the method we erroneously added (by calling B.new after this class body)

@headius
Copy link
Member

headius commented Jan 6, 2015

The bug is in coercion using &. It should kick out the unbound method. Investigating.

~/projects/jruby/rack/rack $ jruby -e "p &Class.instance_method(:new)"

~/projects/jruby/rack/rack $ rvm ruby-2.2 do ruby -e "p &Class.instance_method(:new)"
-e:1:in `<main>': wrong argument type UnboundMethod (expected Proc) (TypeError)

@headius
Copy link
Member

headius commented Jan 6, 2015

Turns out UnboundMethod has not extended Method since 2003. See ruby/ruby@ed0b577.

Fixed in 72234f9.

@headius headius closed this as completed Jan 6, 2015
headius added a commit that referenced this issue Oct 30, 2019
=== 2.7.10 / 2019-06-14

Minor enhancements:

* Fix bundler rubygems binstub not properly looking for bundler. Pull request #2426
  by David Rodríguez.
* [BudlerVersionFinder] set .filter! and .compatible? to match only on major versions.
  Pull request #2515 by Colby Swandale.
+ Update for compatibilty with new minitest. Pull request #2118 by MSP-Greg.
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