Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.1.6
-
Fix Version/s: JRuby 1.2
-
Component/s: Java Integration
-
Labels:None
-
Testcase included:yes
-
Patch Submitted:Yes
-
Number of attachments :
Description
Currently, they are coerced to java.lang.Long and java.lang.Double, respectively, regardless of whether they fit in something smaller, like java.lang.Short or java.lang.Float. This causes problems with some APIs like JMX, which has a generic mechanism for setting attribute values using Object but expects a value that "fits" in the parameter of the target method.
To reproduce, compile the attached java class and run it with:
java -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=10000 -Dcom.sun.management.jmxremote.ssl=false Main
And run the attached ruby script with:
jruby test.rb
You'll get the following exception:
com/sun/jmx/mbeanserver/MBeanIntrospector.java:256:in `maybeInvalidParameter': javax.management.InvalidAttributeValueException: Invalid value for attribute Value: 1 (NativeException)
from com/sun/jmx/mbeanserver/MBeanIntrospector.java:242:in `invokeSetter'
from com/sun/jmx/mbeanserver/PerInterface.java:84:in `setAttribute'
from com/sun/jmx/mbeanserver/MBeanSupport.java:240:in `setAttribute'
from javax/management/StandardMBean.java:369:in `setAttribute'
from com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java:762:in `setAttribute'
from com/sun/jmx/mbeanserver/JmxMBeanServer.java:699:in `setAttribute'
...
Fixed in commit 8805. This is a change in Java Integration behavior, and it will be slightly slower (a few more simple inequality checks – drop in the bucket), but we get plenty of reports of this problem and it seems like this is what people expect behaviorally almost always. To tell the truth I would be surprised if this breaks any existing software. It certainly will make us work with more Java libraries out of the box.