From 0064d399be32fcef7e79560079053826bf2aed8d Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 17 Mar 2021 10:15:25 +0300 Subject: [PATCH] Fix bug in Arrays.binarySearch --- .../org/teavm/classlib/java/util/TArrays.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java b/classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java index c73a90d0e..43dba5512 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java @@ -977,6 +977,9 @@ public class TArrays extends TObject { if (fromIndex > toIndex) { throw new TIllegalArgumentException(); } + if (fromIndex == toIndex) { + return -1; + } int l = fromIndex; int u = toIndex - 1; while (true) { @@ -1006,6 +1009,9 @@ public class TArrays extends TObject { if (fromIndex > toIndex) { throw new TIllegalArgumentException(); } + if (fromIndex == toIndex) { + return -1; + } int l = fromIndex; int u = toIndex - 1; while (true) { @@ -1035,6 +1041,9 @@ public class TArrays extends TObject { if (fromIndex > toIndex) { throw new TIllegalArgumentException(); } + if (fromIndex == toIndex) { + return -1; + } int l = fromIndex; int u = toIndex - 1; while (true) { @@ -1064,6 +1073,9 @@ public class TArrays extends TObject { if (fromIndex > toIndex) { throw new TIllegalArgumentException(); } + if (fromIndex == toIndex) { + return -1; + } int l = fromIndex; int u = toIndex - 1; while (true) { @@ -1093,6 +1105,9 @@ public class TArrays extends TObject { if (fromIndex > toIndex) { throw new TIllegalArgumentException(); } + if (fromIndex == toIndex) { + return -1; + } int l = fromIndex; int u = toIndex - 1; while (true) { @@ -1122,6 +1137,9 @@ public class TArrays extends TObject { if (fromIndex > toIndex) { throw new TIllegalArgumentException(); } + if (fromIndex == toIndex) { + return -1; + } int l = fromIndex; int u = toIndex - 1; while (true) { @@ -1151,6 +1169,9 @@ public class TArrays extends TObject { if (fromIndex > toIndex) { throw new TIllegalArgumentException(); } + if (fromIndex == toIndex) { + return -1; + } int l = fromIndex; int u = toIndex - 1; while (true) { @@ -1188,6 +1209,9 @@ public class TArrays extends TObject { if (fromIndex > toIndex) { throw new TIllegalArgumentException(); } + if (fromIndex == toIndex) { + return -1; + } int l = fromIndex; int u = toIndex - 1; while (true) {