Re: Index 1 is out of bounds



Diego,

s := ReadStream on: #(3 4) asOrderedCollection.
s next: 1

I got an "Index 1 is out of bounds" error. May be it should be reported as
a bug.

Yes, that does look like a bug but, as Bruno said, I think that most
people tend to only stream over ArrayedCollection subclasses (Array
and String for example), and these work correctly. That would
probably explain why this hasn't been noticed before.

The problem stems from the way that OrderedCollections are created
when using #new:. The method comment states

"Answer a new instance of the receiver with sufficient initial
capacity to hold the number of elements specified by the <integer>
argument, count. The instance is initially empty (i.e.it reports 0
when sent #size)."

nb: "the instance is initially empty".

This means that

x := OrderedCollection new: 10.
x at: 5

will answer an error as x is created as a collection with a "capacity"
of 10 elements (i.e. it can accept 10 added elements before needing to
#grow itself) but which, initially, is empty.

The code you quoted creates a new OrderedCollection (in the
Stream>>next: method) and tries to copy elements from the stream's
collection into this new collection using #at:put: which, as we see
above, will not work.

One possible fix, but which might create performance issues, is to
change the Stream>>next: method to

^self contentsSpecies
withAll:
(self
next: anInteger
into: (Array new: anInteger)
startingAt: 1)

But, IMHO, sticking to ArrayedCollection subclasses is probably a
better bet.


--
Ian

The from address is valid
.



Relevant Pages

  • [Un] Unangband 0.6.1 beta 6 released
    ... I\'ve had lots of bug reports and feedback, as well as a winning character since ... if the value on the damage dice roll is less ... Fixed bug when describing sense item effect. ...
    (rec.games.roguelike.angband)
  • Re: kernel bugzilla is FPOS (was: Re: "buggy cmd640" message followed by soft lockup)
    ... Andrew is going through all new bug reports. ... People like Natalie or me also go through new bug reports. ... You can always ask on the list, pointing to the Bugzilla entry in question. ...
    (Linux-Kernel)
  • Re: Delphi makes it to digg!
    ... No, I don't mean here 'names', but from our small experience we found that the best 'field test' is the one who have users from all user levels: ... someone will send you good reports from graphics area. ... for the community to identify and promote issues into the internal bug ... community to use QC, it needs to clearly know that they will have something to gain from there. ...
    (borland.public.delphi.non-technical)
  • Re: kernel bugzilla is FPOS (was: Re: "buggy cmd640" message followed by soft lockup)
    ... Andrew is going through all new bug reports. ... People like Natalie or me also go through new bug reports. ... area without a maintainer looking after the bug. ... You can always ask on the list, pointing to the Bugzilla entry in question. ...
    (Linux-Kernel)
  • BDS needs more bugs fixed
    ... none of the reports I have been interested in have ever been fixed. ... Near the top of this page they have a section "Higher Performance and Better Quality" that says "Over 500 bug reports tracked by our internal system have been fixed in this release. ... Furthermore, the user who reported the problem was still using BCB 6, and he didn't get an update or hotfix, so this issue is not resolved for him unless he pays for an update to BDS 2006 and installs update 2. ... it is a fix for a cosmetic issue only. ...
    (borland.public.delphi.non-technical)