diff --git a/teavm-classlib/pom.xml b/teavm-classlib/pom.xml
index 1bf13a0ec..da8355cad 100644
--- a/teavm-classlib/pom.xml
+++ b/teavm-classlib/pom.xml
@@ -54,6 +54,9 @@
false
1
+
+ **.ArraysTest
+
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java
index 761cf083e..943794448 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java
@@ -128,10 +128,10 @@ public class TArrayList extends TAbstractList implements TCloneable, TSeri
}
ensureCapacity(size + c.size());
int gap = c.size();
- size += gap;
- for (int i = gap - 1; i > index; --i) {
- array[i] = array[i - gap];
+ for (int i = size - 1; i >= index; --i) {
+ array[i + gap] = array[i];
}
+ size += gap;
TIterator extends E> iter = c.iterator();
for (int i = 0; i < gap; ++i) {
array[index++] = iter.next();
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java
index 9cc2a55d3..10598dd18 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java
@@ -182,4 +182,99 @@ public class TArrays extends TObject {
public static void fill(TObject[] a, TObject val) {
fill(a, 0, a.length, val);
}
+
+
+ public static void sort(Object[] a) {
+ sort(a, new NaturalOrder());
+ }
+
+ public static void sort(Object[] a, int fromIndex, int toIndex) {
+ sort(a, fromIndex, toIndex, new NaturalOrder());
+ }
+
+ private static class NaturalOrder implements TComparator