jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-3646

Array subclass: uniq, flatten, other methods (?) do not clone correctly

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1.6, JRuby 1.2
  • Fix Version/s: JRuby 1.6
  • Component/s: Core Classes/Modules, Intro
  • Labels:
    None

Description

Given this code:

class MyArray < Array
attr_accessor :foo

def initialize
@foo = "bar"
end
end
my_a = MyArray.new
p my_a.uniq.foo
p my_a.flatten.foo
p my_a.foo

This is the output from Jruby 1.3.0RC2 (jruby 1.3.0RC2 (ruby 1.8.6p287) (2009-05-12 eb8fea4) (Java HotSpot(TM) Client VM 1.5.0_16) [i386-java])
nil
nil
"bar"

This is the output from (C) ruby 1.8.6:
"bar"
"bar"
"bar"

Granted this is an unusual case... but it is inconsistent and led to a hard-to-track-down bug.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Thomas E Enebo added a comment - 14/May/09 11:53 AM

Nice find (unfortunately ). Can I ask whether this use case came from some public library or other public code? We are interested in pointers to real-life cases of this that we can point to.

Show
Thomas E Enebo added a comment - 14/May/09 11:53 AM Nice find (unfortunately ). Can I ask whether this use case came from some public library or other public code? We are interested in pointers to real-life cases of this that we can point to.
Hide
Permalink
Billy Reisinger added a comment - 14/May/09 12:24 PM

Sure - I found this while trying to do flatten and uniq on an instance of WillPaginate::Collection, which is a subclass of Array with some additional properties. See http://wiki.github.com/mislav/will_paginate

Show
Billy Reisinger added a comment - 14/May/09 12:24 PM Sure - I found this while trying to do flatten and uniq on an instance of WillPaginate::Collection, which is a subclass of Array with some additional properties. See http://wiki.github.com/mislav/will_paginate
Hide
Permalink
Charles Oliver Nutter added a comment - 14/May/09 6:22 PM

Thanks Billy...can you go ahead and add specs for this to RubySpec, and we'll see about getting it fixed? http://www.rubyspec.org/

Show
Charles Oliver Nutter added a comment - 14/May/09 6:22 PM Thanks Billy...can you go ahead and add specs for this to RubySpec, and we'll see about getting it fixed? http://www.rubyspec.org/
Hide
Permalink
Marcin Mielzynski added a comment - 14/May/09 6:28 PM

It's more an internal dupping issue (btw, we match 1.9 here)

Show
Marcin Mielzynski added a comment - 14/May/09 6:28 PM It's more an internal dupping issue (btw, we match 1.9 here)
Hide
Permalink
Billy Reisinger added a comment - 14/May/09 10:07 PM

Marcin - Yeah, strange! I didn't get exactly the same thing when I tried 1.9, though - I compiled the latest stable release from source and got a third possibility, which is confusing.

ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-darwin9.6.2]

"bar"
nil
"bar"

Charles, I would be happy to add something to the spec, but I guess I'm confused as to what should be happening here - especially since it appears that c ruby 1.8 and 1.9 don't even do the same thing. My opinion is that the 1.8.6 output is correct. If the spec advertises that a method returns a copy of the array with some filtering on the collection (such as uniq or flatten do), it should really copy that object in its entirety, including its state. In the very least, the methods should be consistent - either they should not copy the state of bolted-on properties, or they should - but what c ruby 1.9.1 appears to do is even more confusing.

Show
Billy Reisinger added a comment - 14/May/09 10:07 PM Marcin - Yeah, strange! I didn't get exactly the same thing when I tried 1.9, though - I compiled the latest stable release from source and got a third possibility, which is confusing. ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-darwin9.6.2] "bar" nil "bar" Charles, I would be happy to add something to the spec, but I guess I'm confused as to what should be happening here - especially since it appears that c ruby 1.8 and 1.9 don't even do the same thing. My opinion is that the 1.8.6 output is correct. If the spec advertises that a method returns a copy of the array with some filtering on the collection (such as uniq or flatten do), it should really copy that object in its entirety, including its state. In the very least, the methods should be consistent - either they should not copy the state of bolted-on properties, or they should - but what c ruby 1.9.1 appears to do is even more confusing.
Hide
Permalink
Charles Oliver Nutter added a comment - 15/May/09 10:30 PM

Billy: If it's different in different versions, we should just add the different behaviors with version guards. Brian Ford (brixen on IRC) can point you toward good instructions to do that. And in fact if there's differences between versions, it's even more important we spec it so we clearly understand the differences.

Also, if you feel like what Ruby 1.9.1 does is in error, we should probably raise an issue with ruby-core and see if there's a reason for it.

Show
Charles Oliver Nutter added a comment - 15/May/09 10:30 PM Billy: If it's different in different versions, we should just add the different behaviors with version guards. Brian Ford (brixen on IRC) can point you toward good instructions to do that. And in fact if there's differences between versions, it's even more important we spec it so we clearly understand the differences. Also, if you feel like what Ruby 1.9.1 does is in error, we should probably raise an issue with ruby-core and see if there's a reason for it.
Hide
Permalink
Charles Oliver Nutter added a comment - 05/Jan/10 4:08 PM

RubySpec updates should be created for missing cases, but otherwise this may be an easy one to fix. At least repair the mentioned methods, but a review of other methods that return new Array instances would be useful. Marking as Intro.

Show
Charles Oliver Nutter added a comment - 05/Jan/10 4:08 PM RubySpec updates should be created for missing cases, but otherwise this may be an easy one to fix. At least repair the mentioned methods, but a review of other methods that return new Array instances would be useful. Marking as Intro.
Hide
Permalink
Shih-gian Lee added a comment - 02/Feb/11 3:18 PM - edited

Both C ruby 1.8.7 and 1.9.2 return the same result:

ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.6.0]

"bar"
nil
"bar"

ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]

"bar"
nil
"bar"

Can one of you (Charles or Brian) point me to a sample rubyspec that is using version guards? I am not on IRC all the time. I will try to catch one of you on IRC whenever I can or post questions to dev mailing list.

Show
Shih-gian Lee added a comment - 02/Feb/11 3:18 PM - edited Both C ruby 1.8.7 and 1.9.2 return the same result:
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.6.0]

"bar"
nil
"bar"

ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]

"bar"
nil
"bar"
Can one of you (Charles or Brian) point me to a sample rubyspec that is using version guards? I am not on IRC all the time. I will try to catch one of you on IRC whenever I can or post questions to dev mailing list.
Hide
Permalink
Douglas Campos added a comment - 16/Mar/11 1:05 PM

is this really expected? after all, even MRI docs assert that a new_ary would be returned.

I'm trying to file it at ruby's tracker, but it isn't working for now

Show
Douglas Campos added a comment - 16/Mar/11 1:05 PM is this really expected? after all, even MRI docs assert that a new_ary would be returned. I'm trying to file it at ruby's tracker, but it isn't working for now
Hide
Permalink
Charles Oliver Nutter added a comment - 24/Mar/11 6:44 PM

I'm going to mark this as fixed as of 1.6 (probably was fixed earlier) since we match MRI 1.8.7 and 1.9.2. If it turns out later that ruby-core agrees it's a bug, we can look into altering the behavior.

Show
Charles Oliver Nutter added a comment - 24/Mar/11 6:44 PM I'm going to mark this as fixed as of 1.6 (probably was fixed earlier) since we match MRI 1.8.7 and 1.9.2. If it turns out later that ruby-core agrees it's a bug, we can look into altering the behavior.

People

  • Assignee:
    Charles Oliver Nutter
    Reporter:
    Billy Reisinger
Vote (0)
Watch (2)

Dates

  • Created:
    13/May/09 4:41 PM
    Updated:
    24/Mar/11 6:44 PM
    Resolved:
    24/Mar/11 6:44 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.