Skip to content

Commit

Permalink
Return an empty BibEntry from MVStoreBibEntryRelationDAO in case of p…
Browse files Browse the repository at this point in the history
…arsing error (#11189)
  • Loading branch information
Alexandre CREMIEUX authored and Alexandre CREMIEUX committed Jan 26, 2025
1 parent 57b5c02 commit 16cfd2c
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import java.time.ZoneId;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryPreferences;
Expand Down Expand Up @@ -143,7 +145,7 @@ private static String toString(BibEntry entry) {
return entry.toString();
}

private static BibEntry fromString(String serializedString) {
private static Optional<BibEntry> fromString(String serializedString) {
try {
var importFormatPreferences = new ImportFormatPreferences(
new BibEntryPreferences('$'), null, null, null, null, null
Expand All @@ -153,10 +155,10 @@ private static BibEntry fromString(String serializedString) {
.map(entry -> {
entry.clearField(new UnknownField("_jabref_shared"));
return entry;
})
.orElseThrow();
} catch (Exception e) {
throw new RuntimeException(e);
});
} catch (ParseException e) {
LOGGER.error("An error occurred while parsing from relation MV store.", e);
return Optional.empty();
}
}

Expand All @@ -177,7 +179,8 @@ public BibEntry read(ByteBuffer buff) {
int serializedEntrySize = buff.getInt();
var serializedEntry = new byte[serializedEntrySize];
buff.get(serializedEntry);
return fromString(new String(serializedEntry, StandardCharsets.UTF_8));
return fromString(new String(serializedEntry, StandardCharsets.UTF_8))
.orElse(new BibEntry());
}

@Override
Expand Down

0 comments on commit 16cfd2c

Please sign in to comment.