Skip to content

Commit aa3607c

Browse files
committed
[11049] Fixes scala/bug#11049
1 parent d07cf7e commit aa3607c

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

library/src/scala/collection/IndexedSeqView.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ object IndexedSeqView {
2626
private[this] var current = 0
2727
override def knownSize: Int = self.size - current
2828
def hasNext = current < self.size
29-
def next(): A = {
29+
def next(): A = try {
3030
val r = self.apply(current)
3131
current += 1
3232
r
33+
} catch {
34+
case _: IndexOutOfBoundsException => throw new NoSuchElementException("last of empty iterator")
3335
}
3436
}
3537

library/src/scala/collection/mutable/ArrayBuffer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ object ArrayBuffer extends StrictOptimizedSeqFactory[ArrayBuffer] {
210210

211211
final class ArrayBufferView[A](val array: Array[AnyRef], val length: Int) extends AbstractIndexedSeqView[A] {
212212
@throws[ArrayIndexOutOfBoundsException]
213-
def apply(n: Int) = array(n).asInstanceOf[A]
213+
def apply(n: Int) = if (n < length) array(n).asInstanceOf[A] else throw new IndexOutOfBoundsException(n.toString)
214214
override protected[this] def className = "ArrayBufferView"
215215
}
216216

library/src/scala/collection/mutable/PriorityQueue.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,7 @@ sealed class PriorityQueue[A](implicit val ord: Ordering[A])
247247
*
248248
* @return an iterator over all the elements.
249249
*/
250-
override def iterator: Iterator[A] = new AbstractIterator[A] {
251-
private[this] var i = 1
252-
def hasNext: Boolean = i < resarr.p_size0
253-
def next(): A = {
254-
val n = resarr.p_array(i)
255-
i += 1
256-
toA(n)
257-
}
258-
}
250+
override def iterator: Iterator[A] = resarr.iterator.drop(1)
259251

260252
/** Returns the reverse of this priority queue. The new priority queue has
261253
* the same elements as the original, but the opposite ordering.

0 commit comments

Comments
 (0)