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

Projects
None yet
3 participants
@endofunky
Copy link

endofunky commented Jan 5, 2015

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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 Jan 6, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.