jmx4r icon indicating copy to clipboard operation
jmx4r copied to clipboard

fix for calling operations with Java native types

Open schangj09 opened this issue 12 years ago • 3 comments

Hi, I ran into this known issue in jmx4r: http://code.google.com/p/jmx4r/issues/detail?id=8

Here is a patch that fixes it at least for a int, short and float...

Jeffrey

schangj09 avatar Jun 06 '12 15:06 schangj09

I like the change but i was just wondering: why not support all primitives? You could do something like if primitives.has_key?(required_type.name) with the hash values being Java::java.lang.Float etc

vanne avatar Sep 27 '12 08:09 vanne

Forgot to say the complete list is here: http://kenai.com/projects/jruby/pages/CallingJavaFromJRuby#Java_Primitive_Classes

vanne avatar Sep 27 '12 08:09 vanne

I don't think this pull requests goes quite far enough. I'm running into an issue where an operation needs a java.lang.Integer, but jruby 1.7 creates integers as java.lang.Long objects. Calling the operation blows a huge stack trace unless I manually force the numbers into java.lang.Integers before calling the operation.

It seems like we should try calling to_java with the expected class as given in the required_type, as well as supporting the primitives, and only use to_java(:Object) as a last resort.

I'll try my hand at a pull request for this in the next day or two.

bytheway avatar Mar 06 '13 01:03 bytheway