Skip to content

Array#flatten! call in java_import breaks if we import a class with static to_ary #2324

Closed
@headius

Description

@headius

I attempted to java_import org.jruby.util.TypeConverter and ran into this error inside Array#flatten! logic:

ArgumentError: wrong number of arguments (0 for 2)
     flatten! at org/jruby/RubyArray.java:2839
  java_import at file:/Users/headius/projects/jruby/lib/jruby.jar!/jruby/java/core_ext/object.rb:20
       (root) at file:/Users/headius/projects/jruby/lib/jruby.jar!/jruby/kernel/jruby/type.rb:3
       (root) at file:/Users/headius/projects/jruby/lib/jruby.jar!/jruby/kernel.rb:1
       (root) at file:/Users/headius/projects/jruby/lib/jruby.jar!/jruby/kernel.rb:4
         load at org/jruby/RubyKernel.java:969
       (root) at :1

The cause: flatten attempts to coerce elements to Array by calling to_ary with no arguments, but TypeConverter defines a static utility method to_ary(ThreadContext, IRubyObject).

The associated lines of code are seen in the trace above. I think we should just back off flatten! call and do something dumber and more manual that just requires everything already be an Array. That will avoid any future issues with unusual method names getting called for coercion.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions