Java method needs an "int", but gets a "long"

Hi,

I’m trying to call a javax.crypto.Cipher.init method[1] in JRuby.

Here’s a jirb excerpt:

cipher.init(javax.crypto.Cipher::WRAP_MODE, key_spec)
NameError: no init with arguments matching [class java.lang.Long,
class java.security.spec.RSAPublicKeySpec] on object JavaUtilities

irb(main):152:0> cipher.init(3, key_spec)
NameError: no init with arguments matching [class java.lang.Long,
class java.security.spec.RSAPublicKeySpec] on object JavaUtilities

I’ve made a variety of other attempts to coerce the long into an int,
but it seems as if they always get converted into a Ruby Fixnum before
the init method is run. Is there any way to coerce that 3 into a java
int when the init method is run?

Also the jruby version is “ruby 1.8.6 (2008-05-28 rev 6586)
[x86-jruby1.1.2]”.

Thanks,
Jeff

P.S. JRuby is awesome! Thanks to all the developers on this project!

[1]
http://java.sun.com/javase/6/docs/api/javax/crypto/Cipher.html#init(int,%20java.security.Key)


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Tue, Jun 17, 2008 at 2:51 PM, Jeff D. [email protected] wrote:

irb(main):152:0> cipher.init(3, key_spec)
NameError: no init with arguments matching [class java.lang.Long,
class java.security.spec.RSAPublicKeySpec] on object JavaUtilities

I’ve made a variety of other attempts to coerce the long into an int,
but it seems as if they always get converted into a Ruby Fixnum before
the init method is run. Is there any way to coerce that 3 into a java
int when the init method is run?

Also the jruby version is “ruby 1.8.6 (2008-05-28 rev 6586) [x86-jruby1.1.2]”.

It seems a little verbose and painful, but what about

cipher.init(java.lang.Long.new(3), key_spec)

Could you file a bug too in JIRA? I think we should track this as a
java integration use case to be improved upon.
http://jira.codehaus.org/browse/JRUBY

Thanks,
/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I’m getting the same problem. without solution yet?

On Tue, Apr 26, 2011 at 3:20 PM, Jonatas P. [email protected]
wrote:

I’m getting the same problem. without solution yet?

Have you ever tried this?

opmode = javax.crypto.Cipher::WRAP_MODE
cipher.init(opmode.to_java(java.lang.Integer), key_spec)

-Yoko

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs