Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.6, JRuby 1.6.7
-
Fix Version/s: JRuby 1.7.0.pre1
-
Component/s: Core Classes/Modules
-
Environment:Fedora 14
jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
-
Number of attachments :
Description
When a Fixnum array is created, join works as expected:
a = [1,2,3,4]
a.join('.') -> "1.2.3.4"
When a sub-list is created from an existing Fixnum array, join fails.
b = a[2,3]
b.join('.') ->
TypeError: can't convert Fixnum into String
from org/jruby/RubyArray.java:1871:in `join'
from ...
from org/jruby/RubyKernel.java:1088:in `eval'
from org/jruby/RubyKernel.java:1410:in `loop'
from org/jruby/RubyKernel.java:1197:in `catch'
from org/jruby/RubyKernel.java:1197:in `catch'
from ...
This behaviour only occurs in 1.9 compatibility mode, not 1.8. It occurs in both JRuby 1.6.6 and 1.6.7.
Verified expected behaviour in Ruby 1.8.7; 1.9.3; and JRuby 1.6.7 in 1.8 compatibility mode.
I suspect that the array returned from a subset specification is in some way different than a regularly declared array. I inspected the class and ancestry and they look identical, but the behaviour is clearly different.
The line above in RubyArray.java points to the "join19" method.
I do not see this behavior.
$ cat Downloads/array_join_fail_example.rb p RUBY_DESCRIPTION a = [1,2,3,4] # Create a normal array p a.join('.') # -> "1.2.3.4" # Works as expected b = a[2,3] # get sublist; suspect that b is somehow not exactly # the same class type, though it appears to be a normal array. p b.join('.') # -> #TypeError: can't convert Fixnum into String # from org/jruby/RubyArray.java:1871:in `join' # from ... # from org/jruby/RubyKernel.java:1088:in `eval' # from org/jruby/RubyKernel.java:1410:in `loop' # from org/jruby/RubyKernel.java:1197:in `catch' # from org/jruby/RubyKernel.java:1197:in `catch' # from ... $ jruby Downloads/array_join_fail_example.rb "jruby 1.6.7 (ruby-1.8.7-p357) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]" "1.2.3.4" "3.4"