JRuby

Fixnums & Floats should be coerced to the narrowest java.lang.Number when passed to a java method that expects Object

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major 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 :
    3

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'
...

  1. Main.java
    15/Jan/09 3:02 PM
    1 kB
    Martin Traverso
  2. patch.diff
    15/Jan/09 3:02 PM
    5 kB
    Martin Traverso
  3. test.rb
    15/Jan/09 3:02 PM
    0.6 kB
    Martin Traverso

Activity

Hide
Thomas E Enebo added a comment -

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.

Show
Thomas E Enebo added a comment - 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.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: