Permalink
Browse files

Report size for an IndexOutOfBoundsException on a sequence with a neg…

…ative index more correctly
  • Loading branch information...
1 parent 85869cb commit 311d18e02fbd3096f806a33ce56483d8cf9e08ef @qbg committed Feb 22, 2011
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/jvm/clojure/lang/RT.java
@@ -758,7 +758,16 @@ else if(coll instanceof Sequential) {
if(i == n)
return seq.first();
}
- throw new IndexOutOfBoundsException("Index: " + n + ", Size: " + i);
+ if (n < 0) {
+ if (coll instanceof Counted) {
+ throw new IndexOutOfBoundsException("Index: " + n + ", Size: " +
+ ((Counted) coll).count());
+ } else {
+ throw new IndexOutOfBoundsException("Index: " + n + ", Size: unknown");
+ }
+ } else {
+ throw new IndexOutOfBoundsException("Index: " + n + ", Size: " + i);
+ }
}
else
throw new UnsupportedOperationException(

0 comments on commit 311d18e

Please sign in to comment.