Skip to content

Calling .to_java(Java::byte[]) on a RubyArray doesn't convert to a multi-dimensional byte array, but fails with a TypeError exception #1354

Closed
@bigsur0

Description

@bigsur0

Am I doing something wrong here or should this be supported?

>> ["foo".to_java_bytes].to_java(Java::byte[])
TypeError: wrong argument type #<Class:0x32632915> (expected Array)
    from org/jruby/java/addons/KernelJavaAddons.java:67:in `to_java'
    from (irb):1:in `evaluate'
    from org/jruby/RubyKernel.java:1119:in `eval'
    from org/jruby/RubyKernel.java:1519:in `loop'
    from org/jruby/RubyKernel.java:1282:in `catch'
    from org/jruby/RubyKernel.java:1282:in `catch'
    from /Users/me/.rvm/rubies/jruby-1.7.9/bin/irb:13:in `(root)'

In order to achieve this, I needed to do the following intend:

>> outer = Java::byte[10,0].new
=> [B[[B@78dc256, [B@6bd19ff9, [B@f5dcbbc, [B@56eaab85, [B@48a2d557, [B@3a646802, [B@15e87941, [B@5170a5a3, [B@3a8a9a1a, [B@618b3efc]@7cd4446b
>> foo_bytes = "foo".to_java_bytes
=> byte[102, 111, 111]@54b5360e
>> outer[0] = Java::byte[foo_bytes.size].new
=> byte[0, 0, 0]@417e7d7d
>> outer[0] = foo_bytes
=> byte[102, 111, 111]@54b5360e

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions