Skip to content

Commit d8b2c7e

Browse files
CaptainDaVincitobiasdiez
authored andcommitted
Fixes throwing an exception when 'id' field is present in bib file (#4918)
* Fixes throwing an exception when 'id' field is present in bib file Fixes #4905 * Remove test for id field * Renamed ID_FIELD to INTERNAL_ID_FIELD * Removed unused import
1 parent 23e9e52 commit d8b2c7e

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

Diff for: src/main/java/org/jabref/model/entry/BibEntry.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class BibEntry implements Cloneable {
4545
public static final String OBSOLETE_TYPE_HEADER = "bibtextype";
4646
public static final String KEY_FIELD = "bibtexkey";
4747
public static final String DEFAULT_TYPE = "misc";
48-
protected static final String ID_FIELD = "id";
48+
protected static final String INTERNAL_ID_FIELD = "JabRef-internal-id";
4949
private static final Logger LOGGER = LoggerFactory.getLogger(BibEntry.class);
5050
private static final Pattern REMOVE_TRAILING_WHITESPACE = Pattern.compile("\\s+$");
5151
private final SharedBibEntryData sharedBibEntryData;
@@ -161,7 +161,7 @@ public void setId(String id) {
161161

162162
String oldId = this.id;
163163

164-
eventBus.post(new FieldChangedEvent(this, BibEntry.ID_FIELD, id, oldId));
164+
eventBus.post(new FieldChangedEvent(this, BibEntry.INTERNAL_ID_FIELD, id, oldId));
165165
this.id = id;
166166
changed = true;
167167
}
@@ -408,10 +408,6 @@ public Optional<FieldChange> setField(String name, String value, EntryEventSourc
408408
return Optional.empty();
409409
}
410410

411-
if (BibEntry.ID_FIELD.equals(fieldName)) {
412-
throw new IllegalArgumentException("The field name '" + name + "' is reserved");
413-
}
414-
415411
changed = true;
416412

417413
fields.put(fieldName, value.intern());
@@ -463,10 +459,6 @@ public Optional<FieldChange> clearField(String name) {
463459
public Optional<FieldChange> clearField(String name, EntryEventSource eventSource) {
464460
String fieldName = toLowerCase(name);
465461

466-
if (BibEntry.ID_FIELD.equals(fieldName)) {
467-
throw new IllegalArgumentException("The field name '" + name + "' is reserved");
468-
}
469-
470462
Optional<String> oldValue = getField(fieldName);
471463
if (!oldValue.isPresent()) {
472464
return Optional.empty();

Diff for: src/test/java/org/jabref/model/entry/BibEntryTest.java

-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import static org.junit.jupiter.api.Assertions.assertEquals;
1414
import static org.junit.jupiter.api.Assertions.assertNotEquals;
15-
import static org.junit.jupiter.api.Assertions.assertThrows;
1615

1716
public class BibEntryTest {
1817

@@ -28,16 +27,6 @@ public void tearDown() {
2827
entry = null;
2928
}
3029

31-
@Test
32-
public void notOverrideReservedFields() {
33-
assertThrows(IllegalArgumentException.class, () -> entry.setField(BibEntry.ID_FIELD, "somevalue"));
34-
}
35-
36-
@Test
37-
public void notClearReservedFields() {
38-
assertThrows(IllegalArgumentException.class, () -> entry.clearField(BibEntry.ID_FIELD));
39-
}
40-
4130
@Test
4231
public void getFieldIsCaseInsensitive() throws Exception {
4332
entry.setField("TeSt", "value");

0 commit comments

Comments
 (0)