[MNG-8349] Avoid exceptions with invalid modelVersion (#1848)

This commit is contained in:
Guillaume Nodet 2024-10-24 16:37:25 +02:00 committed by GitHub
parent 7c091a14c9
commit 9f2ef34343
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -1963,8 +1963,7 @@ public class DefaultModelValidator implements ModelValidator {
String[] firstSegments = first.split("\\.");
String[] secondSegments = second.split("\\.");
for (int i = 0; i < Math.max(firstSegments.length, secondSegments.length); i++) {
int result = Long.valueOf(i < firstSegments.length ? firstSegments[i] : "0")
.compareTo(Long.valueOf(i < secondSegments.length ? secondSegments[i] : "0"));
int result = asLong(i, firstSegments).compareTo(asLong(i, secondSegments));
if (result != 0) {
return result;
}
@ -1972,6 +1971,14 @@ public class DefaultModelValidator implements ModelValidator {
return 0;
}
private static Long asLong(int index, String[] segments) {
try {
return Long.valueOf(index < segments.length ? segments[index] : "0");
} catch (NumberFormatException e) {
return 0L;
}
}
@SuppressWarnings("checkstyle:parameternumber")
private boolean validateBannedCharacters(
String prefix,