Fix IndexOutOfBoundsException from GithubValueParser

This commit is contained in:
Kris De Volder
2019-05-15 11:25:23 -07:00
parent 1e07fd438e
commit 30f8e2d48c
2 changed files with 14 additions and 1 deletions

View File

@@ -125,6 +125,19 @@ public class DocumentRegion implements CharSequence, IRegion {
throw new IndexOutOfBoundsException(""+offset);
}
}
/**
* Like charAt, but doesn't IndexOutOfBoundsException. Instead it
* return (char)0.
*/
public char safeCharAt(int offset) {
try {
return charAt(offset);
} catch (IndexOutOfBoundsException e) {
return 0;
}
}
/**
* Determines whether this range contains a given (absolute) offset.

View File

@@ -89,7 +89,7 @@ public class GithubValueParsers {
for (String expectedPrefix : GithubRepoContentAssistant.URI_PREFIXES) {
int lastChar = expectedPrefix.length()-1;
if (str.startsWith(expectedPrefix.substring(0, lastChar))) {
char actualSeparator = str.charAt(lastChar);
char actualSeparator = str.safeCharAt(lastChar);
char expectedSeparator = expectedPrefix.charAt(lastChar);
if (actualSeparator==expectedSeparator) {
return expectedPrefix;