Fix bug in Arrays.binarySearch

This commit is contained in:
Alexey Andreev 2021-03-17 10:15:25 +03:00
parent a3eaa1fc18
commit 0064d399be

View File

@ -977,6 +977,9 @@ public class TArrays extends TObject {
if (fromIndex > toIndex) { if (fromIndex > toIndex) {
throw new TIllegalArgumentException(); throw new TIllegalArgumentException();
} }
if (fromIndex == toIndex) {
return -1;
}
int l = fromIndex; int l = fromIndex;
int u = toIndex - 1; int u = toIndex - 1;
while (true) { while (true) {
@ -1006,6 +1009,9 @@ public class TArrays extends TObject {
if (fromIndex > toIndex) { if (fromIndex > toIndex) {
throw new TIllegalArgumentException(); throw new TIllegalArgumentException();
} }
if (fromIndex == toIndex) {
return -1;
}
int l = fromIndex; int l = fromIndex;
int u = toIndex - 1; int u = toIndex - 1;
while (true) { while (true) {
@ -1035,6 +1041,9 @@ public class TArrays extends TObject {
if (fromIndex > toIndex) { if (fromIndex > toIndex) {
throw new TIllegalArgumentException(); throw new TIllegalArgumentException();
} }
if (fromIndex == toIndex) {
return -1;
}
int l = fromIndex; int l = fromIndex;
int u = toIndex - 1; int u = toIndex - 1;
while (true) { while (true) {
@ -1064,6 +1073,9 @@ public class TArrays extends TObject {
if (fromIndex > toIndex) { if (fromIndex > toIndex) {
throw new TIllegalArgumentException(); throw new TIllegalArgumentException();
} }
if (fromIndex == toIndex) {
return -1;
}
int l = fromIndex; int l = fromIndex;
int u = toIndex - 1; int u = toIndex - 1;
while (true) { while (true) {
@ -1093,6 +1105,9 @@ public class TArrays extends TObject {
if (fromIndex > toIndex) { if (fromIndex > toIndex) {
throw new TIllegalArgumentException(); throw new TIllegalArgumentException();
} }
if (fromIndex == toIndex) {
return -1;
}
int l = fromIndex; int l = fromIndex;
int u = toIndex - 1; int u = toIndex - 1;
while (true) { while (true) {
@ -1122,6 +1137,9 @@ public class TArrays extends TObject {
if (fromIndex > toIndex) { if (fromIndex > toIndex) {
throw new TIllegalArgumentException(); throw new TIllegalArgumentException();
} }
if (fromIndex == toIndex) {
return -1;
}
int l = fromIndex; int l = fromIndex;
int u = toIndex - 1; int u = toIndex - 1;
while (true) { while (true) {
@ -1151,6 +1169,9 @@ public class TArrays extends TObject {
if (fromIndex > toIndex) { if (fromIndex > toIndex) {
throw new TIllegalArgumentException(); throw new TIllegalArgumentException();
} }
if (fromIndex == toIndex) {
return -1;
}
int l = fromIndex; int l = fromIndex;
int u = toIndex - 1; int u = toIndex - 1;
while (true) { while (true) {
@ -1188,6 +1209,9 @@ public class TArrays extends TObject {
if (fromIndex > toIndex) { if (fromIndex > toIndex) {
throw new TIllegalArgumentException(); throw new TIllegalArgumentException();
} }
if (fromIndex == toIndex) {
return -1;
}
int l = fromIndex; int l = fromIndex;
int u = toIndex - 1; int u = toIndex - 1;
while (true) { while (true) {