ANDROID: Avoid crash if version no is not int

This can happen during development - shouldn't happen for any official release,
but even if it does let's just assume versions are different and default to
upgrading the config.
This commit is contained in:
Matthew Duggan 2020-10-20 20:41:38 +09:00
parent 16a105cdbb
commit e1bff1cbb3

View file

@ -36,15 +36,19 @@ public class Version implements Comparable<Version> {
String[] thisParts = this.get().split("\\.");
String[] thatParts = that.get().split("\\.");
int length = Math.max(thisParts.length, thatParts.length);
for(int i = 0; i < length; i++) {
int thisPart = i < thisParts.length ?
Integer.parseInt(thisParts[i]) : 0;
int thatPart = i < thatParts.length ?
Integer.parseInt(thatParts[i]) : 0;
if(thisPart < thatPart)
return -1;
if(thisPart > thatPart)
return 1;
try {
for (int i = 0; i < length; i++) {
int thisPart = i < thisParts.length ?
Integer.parseInt(thisParts[i]) : 0;
int thatPart = i < thatParts.length ?
Integer.parseInt(thatParts[i]) : 0;
if (thisPart < thatPart)
return -1;
if (thisPart > thatPart)
return 1;
}
} catch (NumberFormatException e) {
return 1;
}
return 0;
}