Fix FqNameUnsafe.startsWith() when first segment of fqName is shorter than given segment

FqNameUnsafe("c.C").startsWith("cnames")
must return false
It's a refix of fdf826208f
This commit is contained in:
Vladimir Sukharev
2023-12-06 09:56:58 +01:00
committed by Space Team
parent 0dd24a4de9
commit 93af9f33e4
2 changed files with 53 additions and 1 deletions
@@ -163,8 +163,10 @@ public final class FqNameUnsafe {
return false;
int firstDot = fqName.indexOf('.');
int fqNameFirstSegmentLength = firstDot == -1 ? fqName.length() : firstDot;
String segmentAsString = segment.asString();
return fqName.regionMatches(0, segmentAsString, 0, firstDot == -1 ? Math.max(fqName.length(), segmentAsString.length()) : firstDot);
return fqNameFirstSegmentLength == segmentAsString.length() &&
fqName.regionMatches(0, segmentAsString, 0, fqNameFirstSegmentLength);
}
public boolean startsWith(@NotNull FqNameUnsafe other) {