Skip to content

Inconsistency between MRI and JRuby when private methods are called and method_missing is present #540

@jvshahid

Description

@jvshahid
#!/usr/bin/env ruby
class Foo
  def method_missing name
    super
  end
  private
  def foo
    'foo'
  end
end

Foo.new.foo

this code will generate an exception with different messages under MRI and JRuby.

MRI:

/home/jvshahid/foo.rb:4:in `method_missing': private method `foo' called for #<Foo:0x00000001eed260> (NoMethodError)
    from /home/jvshahid/foo.rb:14:in `<main>'

JRuby:

NoMethodError: undefined method `foo' for #<Foo:0x64e137c0>
  method_missing at org/jruby/RubyBasicObject.java:1652
  method_missing at /home/jvshahid/foo.rb:4
          (root) at /home/jvshahid/foo.rb:12

Notice that JRuby's exception doesn't mention that the method we're trying to access is private. This cause three specs to fail in rails since unfortunately they rely on the wording of the exception.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions