This is from the Ruboto project. I have included the larger problem to
encourage new ideas for solutions.
We have an option hash that is converted to Java setter method calls.
Today we use “send” with the adapted method name and the given
arguments. Now we want to allow sending “int” arguments defined by Ruby
hex literals like 0xFFB90706. In Ruby this becomes a positive Integer,
while in Java this literal becomes a negative int. When trying to call
a Java method accepting an int argument we get the error “too big for
int: 4290316038” which is reasonable since we try to send a number
larger than an int can hold.
So we want to subtract 0x100000000 from arguments to int parameters if
their value is between 0x80000000 and 0xFFFFFFFF
We only want to do this for int parameters, and we do not want to
interfere with the regular JRuby election of which method to call.
Especially if there is an overloaded method with an implementation that
accepts a long instead of the int, we want that method to be called as
How do we best do this? Any advice is appreciated.
Our current code:
method_name = “setMargin”
args = [0xFFB90706] # this should be converted to [-0x46F8FA]
We have tried a few things, but it boils down to getting the correct
method without knowing the parameter types. We need an answer to this
query: “Give me the method with the given name that would be called on
this object with the given arguments.” We would then iterate over the
arguments and parameter types and convert the int arguments that fit our