Skip to content

Commit 16cfd2c

Browse files
Alexandre CREMIEUXAlexandre CREMIEUX
Alexandre CREMIEUX
authored and
Alexandre CREMIEUX
committed
Return an empty BibEntry from MVStoreBibEntryRelationDAO in case of parsing error (JabRef#11189)
1 parent 57b5c02 commit 16cfd2c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/java/org/jabref/logic/citation/repository/MVStoreBibEntryRelationDAO.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import java.time.ZoneId;
1111
import java.util.LinkedHashSet;
1212
import java.util.List;
13+
import java.util.Optional;
1314
import java.util.stream.Collectors;
1415
import java.util.stream.IntStream;
1516

1617
import org.jabref.logic.importer.ImportFormatPreferences;
18+
import org.jabref.logic.importer.ParseException;
1719
import org.jabref.logic.importer.fileformat.BibtexParser;
1820
import org.jabref.model.entry.BibEntry;
1921
import org.jabref.model.entry.BibEntryPreferences;
@@ -143,7 +145,7 @@ private static String toString(BibEntry entry) {
143145
return entry.toString();
144146
}
145147

146-
private static BibEntry fromString(String serializedString) {
148+
private static Optional<BibEntry> fromString(String serializedString) {
147149
try {
148150
var importFormatPreferences = new ImportFormatPreferences(
149151
new BibEntryPreferences('$'), null, null, null, null, null
@@ -153,10 +155,10 @@ private static BibEntry fromString(String serializedString) {
153155
.map(entry -> {
154156
entry.clearField(new UnknownField("_jabref_shared"));
155157
return entry;
156-
})
157-
.orElseThrow();
158-
} catch (Exception e) {
159-
throw new RuntimeException(e);
158+
});
159+
} catch (ParseException e) {
160+
LOGGER.error("An error occurred while parsing from relation MV store.", e);
161+
return Optional.empty();
160162
}
161163
}
162164

@@ -177,7 +179,8 @@ public BibEntry read(ByteBuffer buff) {
177179
int serializedEntrySize = buff.getInt();
178180
var serializedEntry = new byte[serializedEntrySize];
179181
buff.get(serializedEntry);
180-
return fromString(new String(serializedEntry, StandardCharsets.UTF_8));
182+
return fromString(new String(serializedEntry, StandardCharsets.UTF_8))
183+
.orElse(new BibEntry());
181184
}
182185

183186
@Override

0 commit comments

Comments
 (0)