<br><br><div class="gmail_quote">On Sun, Jul 10, 2011 at 10:53 AM, Levente Uzonyi <span dir="ltr">&lt;<a href="mailto:leves@elte.hu">leves@elte.hu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Mon, 11 Jul 2011, Ben Coman wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I am writing some code that uses OrderedCollection and was tracing through it with the debugger when the debugger itself threw a DNU exception.  I narrowed down reproduction of this to executing the following line, clicking &lt;Debug&gt; then eight times &lt;Into&gt; :<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    self halt. OrderedCollection new: 5.<br>
</blockquote>
<br>
As far as I can determine, the root cause is that &quot;OrderedCollectionInspector&gt;&gt;<u></u>fieldList&quot; calls &quot;object size&quot; which has the following implementation:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    OrderedCollection&gt;&gt;size<br>
       ^ lastIndex - firstIndex + 1<br>
</blockquote>
<br>
where &quot;lastIndex&quot; is nil (and also &quot;firstIndex&quot; is nil).<br>
To narrow it down further, the error can also be reproduced by executing the following:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
OrderedCollectionInspector openOn: OrderedCollection basicNew.<br>
</blockquote>
<br>
I fixed this with:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    OrderedCollection&gt;&gt;size<br>
       lastIndex ifNil: [ ^0 ].<br>
       ^ lastIndex - firstIndex + 1<br>
</blockquote>
<br>
It would be more correct to also have included &quot;firstIndex ifNil: [ ^0 ]&quot; but I assume both conditions occur at the same time, so I left it out for performance. Not knowing how performance issue are balanced in Squeak, I was concerned that the &quot;size&quot; method might be called very often, and that even this one extra line might want to be avoided - I assume that  this case only occurs in debugging at times when the object has not been fully initialized, and this error would not occur from application code.  So I went looking for an<br>

</blockquote>
<br>
Right.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
alternative.  Back in the caller, rather than:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    OrderedCollection&gt;&gt;fieldList<br>
        object ifNil: [ ^ OrderedCollection new].<br>
        ^ self baseFieldList ,<br>
            (object size &lt;= (self i1 + self i2)<br>
</blockquote>
&lt;snip&gt;<br>
<br>
this corrected the problem:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    OrderedCollection&gt;&gt;fieldList<br>
        object ifNil: [ ^ OrderedCollection new].<br>
       [ object size ] on: Exception do: [ ^ self baseFieldList ].<br>
        ^ self baseFieldList ,<br>
            (object size &lt;= (self i1 + self i2)<br>
</blockquote>
&lt;snip&gt;<br>
I assume this would also be required for OrderedCollection&gt;&gt;<u></u>selectedObjectIndex.<br>
</blockquote>
<br>
Yes, OrderedCollectionInspector should be changed, because that&#39;s what causes the problem. I&#39;d simply create an #objectSize method for it and use that instead of object size.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
However now in the debugger inst-var sub-pane, selecting self shows &quot;&lt;error in printString: evaluate &quot;self printString&quot; to debug&gt;, and in so doing reveals that the &quot;self size&quot; call fails in:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    OrderedCollection&gt;&gt;do: elementBlock separatedBy: separatorBlock<br>
        1 to: self size do:<br>
</blockquote></blockquote>
<br>
IMHO this is not a problem. #printString doesn&#39;t have to work for uninitialized objects.<br></blockquote><div><br></div><div>+100.  One can&#39;t distort production code for the benefit of debugging.  One can make the debugger robust, e.g. in the presence of faulty printing code, and the debugger and inspector already are robust in this way.  I don&#39;t see the need of any changes here (other than the arguable firstIndex ifNil: [^0]&quot;.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
<br>
Levente<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
indicating a similar fix is potentially required for the following methods:<br>
  OrderedCollection&gt;&gt;add: newObject afterIndex: index<br>
  OrderedCollection&gt;&gt;add: newObject beforeIndex: index<br>
  OrderedCollection&gt;&gt;at: index ifAbsentPut: block<br>
  OrderedCollection&gt;&gt;collect: aBlock<br>
  OrderedCollection&gt;&gt;<u></u>copyReplaceFrom: start to: stop with: replacementCollection<br>
  OrderedCollection&gt;&gt;<u></u>makeRoomAtFirst<br>
  OrderedCollection&gt;&gt;<u></u>makeRoomAtLast<br>
  OrderedCollection&gt;&gt;<u></u>postCopyFrom: startIndex to: endIndex<br>
  OrderedCollection&gt;&gt;with: otherCollection collect: twoArgBlock<br>
  OrderedCollection&gt;&gt;<u></u>withIndexCollect: elementAndIndexBlock<br>
which is not as clean as modifying OrderedCollection&gt;&gt;size, and still a bit uncertain.<br>
<br>
What is the community&#39;s thoughts on this?<div class="im"><br>
<br>
Finally, if any of these are desirable fixes, I would appreciate using my first contribution as a practice for submitting to the Inbox (if someone could direct me to some documentation that describes how to do this.)<br>

<br>
cheers, Ben<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div></blockquote>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>best,<div>Eliot</div><br>