Skip to content

Kernel#inspect calls method_missing for instance_variables_to_inspect even when respond_to_missing? is false #10012

Open

Description

@janko

Environment Information

  • jruby 10.1.0.0 (4.0.0) 2026-04-20 32f988b78c OpenJDK 64-Bit Server VM 21.0.1 on 21.0.1 +indy +jit [arm64-darwin]
  • Also reproduced on GitHub Actions (ubuntu-latest) with jruby 10.1.2.0 (4.0.0) 2026-09-21 36cf8bbe87
  • As far as I can tell, 10.1.3.0 has the same code path (RubyBasicObject#hashyInspect uses Helpers.invokeChecked for instance_variables_to_inspect)

Expected Behavior

When an object doesn't define instance_variables_to_inspect, Kernel#inspect shouldn't send it through method_missing unless respond_to_missing? returns true. CRuby uses rb_check_funcall here, which checks respond_to_missing? before it calls method_missing:

class Foo
  def initialize
    @bar = 1
  end

  def method_missing(name, *args)
    self
  end
end

p Foo.new.respond_to?(:instance_variables_to_inspect) # => false
puts Foo.new.inspect
$ ruby -v repro.rb
ruby 4.0.7 (2026-09-15 revision 229531a6cf) +PRISM [arm64-darwin25]
false
#<Foo:0x00000001203761a0 @bar=1>

Actual Behavior

JRuby calls method_missing(:instance_variables_to_inspect) and then raises because the return value isn't an Array:

$ jruby -v repro.rb
jruby 10.1.0.0 (4.0.0) 2026-04-20 32f988b78c OpenJDK 64-Bit Server VM 21.0.1 on 21.0.1 +indy +jit [arm64-darwin]
false
TypeError: Expected #instance_variables_to_inspect to return an Array or nil, but it returned Foo
  inspect at org/jruby/RubyKernel.java:2286
   <main> at repro.rb:12

Found via MiniMagick, where MiniMagick::Tool#method_missing turns any undefined method into a CLI option and returns self. Because of this, inspect fails on every MiniMagick::Tool instance on JRuby 10.1.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions