mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-22 17:18:40 +01:00
Fix IndexOutOfBoundsException if error log is empty
Affects issues: - Fixed #2224
This commit is contained in:
parent
8bded98f0f
commit
9ae2c07920
@ -125,16 +125,15 @@ public class PluginErrorLogger implements ErrorLogger {
|
||||
|
||||
private void logExisting(Path errorLog, Throwable throwable, ErrorContext context, String hash) {
|
||||
// Read existing
|
||||
List<String> lines;
|
||||
try (Stream<String> read = Files.lines(errorLog)) {
|
||||
lines = read.collect(Collectors.toList());
|
||||
} catch (IOException e) {
|
||||
List<String> lines = read.collect(Collectors.toList());
|
||||
|
||||
int occurrences = getOccurrences(lines) + 1;
|
||||
List<String> newLines = buildNewLines(context, lines, occurrences, hash);
|
||||
overwrite(errorLog, throwable, newLines);
|
||||
} catch (IOException | IndexOutOfBoundsException e) {
|
||||
logAfterReadError(errorLog, throwable, context, hash);
|
||||
return;
|
||||
}
|
||||
int occurrences = getOccurrences(lines) + 1;
|
||||
List<String> newLines = buildNewLines(context, lines, occurrences, hash);
|
||||
overwrite(errorLog, throwable, newLines);
|
||||
}
|
||||
|
||||
private void overwrite(Path errorLog, Throwable throwable, List<String> newLines) {
|
||||
@ -184,6 +183,8 @@ public class PluginErrorLogger implements ErrorLogger {
|
||||
}
|
||||
|
||||
private int getOccurrences(List<String> lines) {
|
||||
if (lines.isEmpty()) return 0;
|
||||
|
||||
String occurLine = lines.get(0);
|
||||
return Integer.parseInt(StringUtils.splitByWholeSeparator(occurLine, ": ")[2].trim());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user