Skip to content

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

@endofunky

Description

@endofunky

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'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions