8000 ArrayList.removeRange throws IndexOutOfBoundsException in JS · scala-js/scala-js@a1da481 · GitHub
[go: up one dir, main page]

Skip to content

Commit a1da481

Browse files
committed
ArrayList.removeRange throws IndexOutOfBoundsException in JS
removeRange should throws an `IndexOutOfBoundsException` if fromIndex or toIndex is out of range.
1 parent d2a52a4 commit a1da481

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

javalib/src/main/scala/java/util/ArrayList.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ class ArrayList[E] private (innerInit: AnyRef, private var _size: Int)
169169
}
170170
}
171171

172-
override protected def removeRange(fromIndex: Int, toIndex: Int): Unit =
172+
override protected def removeRange(fromIndex: Int, toIndex: Int): Unit = {
173+
if (fromIndex < 0 || toIndex > size() || toIndex < fromIndex) {
174+
throw new IndexOutOfBoundsException()
175+
}
173176
if (isWebAssembly) {
174177
if (fromIndex != toIndex) {
175-
if (fromIndex < 0 || toIndex > size() || toIndex < fromIndex) {
176-
throw new IndexOutOfBoundsException()
177-
}
178178
System.arraycopy(innerWasm, toIndex, innerWasm, fromIndex, size() - toIndex)
179179
for (i <- (size() - toIndex + fromIndex) until size()) {
180180
innerWasm(i) = null
@@ -184,6 +184,7 @@ class ArrayList[E] private (innerInit: AnyRef, private var _size: Int)
184184
} else {
185185
innerJS.splice(fromIndex, toIndex - fromIndex)
186186
}
187+
}
187188

188189
// Wasm only
189190
private def expand(): Unit = {

test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/util/ArrayListTest.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ package org.scalajs.testsuite.javalib.util
1414

1515
import org.junit.Test
1616
import org.junit.Assert._
17-
import org.junit.Assume._
1817

1918
import org.scalajs.testsuite.utils.AssertThrows.assertThrows
2019
import org.scalajs.testsuite.utils.Platform
2120

2221
import java.{util => ju}
2322

2423
import scala.reflect.ClassTag
25-
import scala.scalajs.LinkingInfo
2624

2725
class ArrayListTest extends AbstractListTest {
2826

@@ -70,8 +68,6 @@ class ArrayListTest extends AbstractListTest {
7068
}
7169

7270
@Test def removeRangeFromToInvalidIndices(): Unit = {
73-
assumeTrue("Assume targeting Wasm, JS-based impl doesn't throw.",
74-
LinkingInfo.isWebAssembly)
7571
val al = new ArrayListRangeRemovable[Int](
7672
TrivialImmutableCollection(175, -24, -7, -44))
7773

0 commit comments

Comments
 (0)
0