ICU-7264 fix binary search and avoid IndexOutOfBoundsException from ArrayList.get(limit=size())

X-SVN-Rev: 28903
This commit is contained in:
Markus Scherer 2010-10-25 18:40:00 +00:00
parent 583f5ab6ee
commit e6751083f6

View file

@ -2204,23 +2204,22 @@ final class CollationParsedRuleBuilder {
// using binary search to determine if last expansion element is
// already in the array
int result = -1;
while (start < limit - 1) {
int mid = start + ((limit - start) >> 1);
long unsignedce = (maxexpansion.m_endExpansionCE_
.get(mid)).intValue();
unsignedce &= 0xFFFFFFFFl;
if (unsigned <= unsignedce) {
limit = mid;
} else {
start = mid;
if (limit > 0) {
while (start < limit - 1) {
int mid = (start + limit) >> 1;
long unsignedce = (maxexpansion.m_endExpansionCE_
.get(mid)).intValue();
unsignedce &= 0xFFFFFFFFl;
if (unsigned < unsignedce) {
limit = mid;
} else {
start = mid;
}
}
if ((maxexpansion.m_endExpansionCE_.get(start)).intValue() == endexpansion) {
result = start;
}
}
if ((maxexpansion.m_endExpansionCE_.get(start)).intValue() == endexpansion) {
result = start;
} else if ((maxexpansion.m_endExpansionCE_.get(limit))
.intValue() == endexpansion) {
result = limit;
}
if (result > -1) {
// found the ce in expansion, we'll just modify the size if it