Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6RC1, JRuby 1.6RC2, JRuby 1.6RC3, JRuby 1.6
-
Fix Version/s: JRuby 1.6.1
-
Component/s: Java Integration
-
Labels:None
-
Environment:Windows XP
-
Number of attachments :
Description
In previous versions, the assignement of a Fixnum upto 255 was accepted in assignement, since 1.6 this creates a range error.
Not sure if this behaviour is intneded. I can't find any documentation about this change. I know that Java::byte is signed -128..127 but sofar when bridging Ruby and Java this form of asignment was accepted.
Below : test case is shown.
---------------------
Welcome to the JRuby IRB Console [1.5.6]
irb(main):001:0> b = Java::byte[6].new
#<#<Class:01x1b19753>:0x45ce17>
irb(main):002:0> b[0] = 245
245
irb(main):003:0>
Welcome to the JRuby IRB Console [1.6.0.RC1]
irb(main):001:0> b = Java::byte[6].new
#<#<Class:0x101f35e30>:0xaccd65>
irb(main):002:0> b[0] = 245
RangeError: too big for byte: 245
from org/jruby/java/proxies/ArrayJavaProxy.java:84:in `op_aset'
from (irb):2:in `evaluate'
from org/jruby/RubyKernel.java:1091:in `eval'
from C:/jruby-1.6.0.RC1/lib/ruby/1.8/irb.rb:158:in `eval_input'
from C:/jruby-1.6.0.RC1/lib/ruby/1.8/irb.rb:271:in `signal_status'
from C:/jruby-1.6.0.RC1/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1421:in `loop'
from org/jruby/RubyKernel.java:1194:in `rbCatch'
from C:/jruby-1.6.0.RC1/lib/ruby/1.8/irb.rb:154:in `eval_input'
from C:/jruby-1.6.0.RC1/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1194:in `rbCatch'
from C:/jruby-1.6.0.RC1/lib/ruby/1.8/irb.rb:70:in `start'
irb(main):003:0>
I'm on the fence about this one. For the other types, we also throw a hard error if the incoming value is outside the signed range of the target. This is sometimes a hassle, but if we tried to guess what to do we'd be wrong half the time.
In this case, however, we're talking about bytes, which are very commonly used in their unsigned form. Indeed, we return unsigned byte values from String and IO methods that return bytes, so not being able to stuff a signed Fixnum in the range 0..255 into an 8-bit Java byte is definitely problematic.
Perhaps the "right" way to do this would be to convert values in the range 128..255 to their signed bits equivalent and allow them through? I hate adding exceptions like this, but if it's not there it's a bit painful to pass a full range of 8-bit values to Java.
What do others think?
In the interim you could simply convert values in that range to their signed equivalent and it should work...