From 5035c58533b6aed9ede9050235aacdaf108baa42 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 23 Oct 2018 17:01:55 +0300 Subject: [PATCH] Fix Collections.reverse for non-random access lists. Make ArrayList random access. --- .../src/main/java/org/teavm/classlib/java/util/TArrayList.java | 2 +- .../main/java/org/teavm/classlib/java/util/TCollections.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java b/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java index f5b31f338..22728d3b7 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java @@ -21,7 +21,7 @@ import org.teavm.classlib.java.lang.*; import org.teavm.classlib.java.util.function.TUnaryOperator; import org.teavm.interop.Rename; -public class TArrayList extends TAbstractList implements TCloneable, TSerializable { +public class TArrayList extends TAbstractList implements TCloneable, TSerializable, TRandomAccess { private E[] array; private int size; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TCollections.java b/classlib/src/main/java/org/teavm/classlib/java/util/TCollections.java index 47045d271..a03427399 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TCollections.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TCollections.java @@ -224,7 +224,7 @@ public class TCollections extends TObject { reverse(list, 0, list.size()); } else { TList randomAccess = new TArrayList<>(list); - reverse(list, 0, list.size()); + reverse(randomAccess, 0, randomAccess.size()); list.clear(); ((TList) list).addAll(randomAccess); }