Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Dec 20, 2013 · 2 comments
Assignees
Milestone

Comments

@bigsur0
Copy link
Contributor

bigsur0 commented Dec 20, 2013

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
@bigsur0
Copy link
Contributor Author

bigsur0 commented Dec 20, 2013

This variant doesn't seem to work either.

>> ["foo".to_java_bytes].to_java(Java::byte[].java_class)
TypeError: unable to convert to type: [B
    from org/jruby/java/addons/KernelJavaAddons.java:64:in `to_java'
    from (irb):5:in `evaluate'
    from org/jruby/RubyKernel.java:1123:in `eval'
    from org/jruby/RubyKernel.java:1519:in `loop'
    from org/jruby/RubyKernel.java:1284:in `catch'
    from org/jruby/RubyKernel.java:1284:in `catch'
    from /Users/me/.rvm/rubies/jruby-1.7.8/bin/irb:13:in `(root)'

@kares kares self-assigned this Mar 23, 2015
kares added a commit to kares/jruby that referenced this issue Mar 26, 2015
…ray + cleanup

najs to have ... has been reported as well jruby#1354
@kares kares added this to the JRuby 1.7.20 milestone Mar 26, 2015
@kares
Copy link
Member

kares commented Mar 26, 2015

multi-dimensional arrays have been converting fine for a while but still cases such as a Ruby array with a nested Java array where not handled ... but this should now be working as well (since 1.7.20), thank you!

@kares kares closed this as completed Mar 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants