arton / rjb

Ruby Java Bridge
https://www.artonx.org/collabo/backyard/?RubyJavaBridge
GNU Lesser General Public License v2.1
117 stars 34 forks source link

Can't _invoke methods with primitives #19

Closed keithrbennett closed 11 years ago

keithrbennett commented 11 years ago

I'm trying to call a Java function function that takes an array of byte primitives (byte []) and a string. I've tried both of these but both produce an error:

    java_validator._invoke('validateMessage', '[B;Ljava.lang.String;', wire_data, zone)
    java_validator._invoke('validateMessage', '[b;Ljava.lang.String;', wire_data, zone)

In contrast, another call not involving primitives works:

    java_validator._invoke('validateMessage', 'Lorg.xbill.DNS.Message;Ljava.lang.String;', java_message, zone)

I tried reducing this problem to a simpler form and found that I could not even invoke a function containing a single parameter which was a byte:

public class Keith {
    public void foo(byte b) {
        String s = Byte.toString(b);
        System.out.println("byte is " + s);
    }
}
// (Compile Keith.java in top namespace and directory, then run the following Ruby code:)
require 'rjb'
Keith = Rjb::import 'Keith'
keith = Keith.new
keith.foo(7)
keith._invoke('foo', 'B;', 7)

# Output is:
# byte is 7
# x.rb:5:in `_invoke': Fail: unknown method name `foo('B;')' (RuntimeError)

...meaning the direct call to foo() worked, but the call using _invoke did not. I also tried a lower case 'b', but that failed as well.

Is this a bug or am I doing something wrong?

Thanks, Keith

arton commented 11 years ago

Hi Keith

The signature string is bit complicated. The terminator character ';' is only required for the class name. So you may write the first example as java_validator._invoke('validateMessage', '[BLjava.lang.String;', wire_data, zone); Between B and L is nothing. The second reduced example (thanks for the reduced example I always need it) as keith._invoke('foo', 'B', 7);

Best regards.