inconsistencies or errors of range checks for integers passed to int, short and byte arguments of Java methods --------------------------------------------------------------------------------------------------------------
Key: JRUBY-5120 URL: http://jira.codehaus.org/browse/JRUBY-5120 Project: JRuby Issue Type: Bug Components: Java Integration Affects Versions: JRuby 1.5.2 Environment: MS Windows Vista, but I suspect that if this is a bug then it won't just be in JRuby for MS Windows Reporter: Colin Bartlett Priority: Minor Attachments: JR_test_integer_arg_range.bat, JR_test_integer_arg_range.java, JR_test_integer_arg_range.rb Currently both JRuby 1.5.2 and 1.5.3 seem to allow integer values in the range (2**31) .. ((2**32) - 1) for Java int arguments, albeit changing these values to negative values. (Integer overflow?) I haven't tried this in earlier JRuby versions. And is there a similar problem for short and byte arguments? Range (2**15) .. ((2**16) - 1) seems to be allowed for Java short arguments. Range (2**7) .. ((2**8) - 1) seems to be allowed for Java byte arguments. The current behaviour (on my Windows Vista laptop) for "too large" int arguments seems wrong to me anyway, but its inconsistency with the behaviour for "too large" long arguments makes me more confident that it's probably a bug. That said, I'm somewhat less confident that this is a bug because of the similar behaviour for short and byte arguments. But maybe this is also essentially the same problem for those? I've looked at the bugs reported in 2010 and couldn't find anything which seemed to cover this. Also: currently if a Bignum is being passed to a int, short or byte the error message is: "#<RangeError: bignum too big to convert into `long'>" As a suggestion, if it's not too awkward too implement, could the error message be: "#<RangeError: bignum too big for int>" (and similarly for short and byte), making it more consistent with the current error messages for smaller "too large" integers, for example: "#<RangeError: too big for int: 4294967296>" but omitting the (possibly *very* large) too big number. Is perhaps the reason for the current error messages that JRuby: 1: detects the integer is too big for the int [or short or byte] argument; 2: intends to raise the "too big for int [short, byte]: 9999999999" error; 3: so tries to convert the "too large" integer to a Java long for display in the error message; and *that* raises the "bignum too big to convert into `long'" exception which is actually raised? Or something like that? I am very willing to (try to) answer any questions on any of this. Colin Bartlett -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email