<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -26,6 +26,7 @@
 @import &quot;CPSortDescriptor.j&quot;
 @import &quot;CPException.j&quot;
 
+
 /* @ignore */
 @implementation _CPArrayEnumerator : CPEnumerator
 {
@@ -520,6 +521,9 @@
 */
 - (id)objectAtIndex:(int)anIndex
 {
+    if (anIndex &gt;= length)
+        [CPException raise:CPRangeException reason:@&quot;index (&quot; + anIndex + @&quot;) beyond bounds (&quot; + length + @&quot;)&quot;];
+
     return self[anIndex];
 }
 </diff>
      <filename>Foundation/CPArray.j</filename>
    </modified>
    <modified>
      <diff>@@ -115,6 +115,46 @@
           equals:2];
 }
 
+- (void)testIndexOutOfBounds
+{
+    try
+    {
+        [[] objectAtIndex:0];
+        [self assert:false];
+    }
+    catch (anException)
+    {
+        [self assert:[anException name] equals:CPRangeException];
+        [self assert:[anException reason] equals:@&quot;index (0) beyond bounds (0)&quot;];
+    }
+
+    [[0, 1, 2] objectAtIndex:0];
+    [[0, 1, 2] objectAtIndex:1];
+    [[0, 1, 2] objectAtIndex:2];
+
+    try
+    {
+        [[0, 1, 2] objectAtIndex:3];
+        [self assert:false];
+    }
+    catch (anException)
+    {
+        [self assert:[anException name] equals:CPRangeException];
+        [self assert:[anException reason] equals:@&quot;index (3) beyond bounds (3)&quot;];
+    }
+
+    try
+    {
+        [[0, 1, 2] objectAtIndex:4];
+        [self assert:false];
+    }
+    catch (anException)
+    {
+        [self assert:[anException name] equals:CPRangeException];
+        [self assert:[anException reason] equals:@&quot;index (4) beyond bounds (3)&quot;];
+    }
+}
+
 @end
 
 @implementation CPArray (reverse)</diff>
      <filename>Tests/Foundation/CPArrayTest.j</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b2f35b61d39ba9233998deae0c16a44c6b23fb34</id>
    </parent>
  </parents>
  <author>
    <name>Francisco Ryan Tolmasky I</name>
    <email>francisco@280north.com</email>
  </author>
  <url>http://github.com/280north/cappuccino/commit/a5a43de26ecda590234341db18f8bb29937eb7fb</url>
  <id>a5a43de26ecda590234341db18f8bb29937eb7fb</id>
  <committed-date>2009-07-08T11:52:47-07:00</committed-date>
  <authored-date>2009-07-08T11:52:47-07:00</authored-date>
  <message>Fix for objectAtIndex: throwing out of range exceptions.

Closes #105.

Reviewed by me.</message>
  <tree>4ca532e57ab3d4235c29e7c50ba1d6b3902f3c7e</tree>
  <committer>
    <name>Francisco Ryan Tolmasky I</name>
    <email>francisco@280north.com</email>
  </committer>
</commit>
