Skip to content

Commit

Permalink
Fixes throwing an exception when 'id' field is present in bib file (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
CaptainDaVinci authored and tobiasdiez committed Apr 24, 2019
1 parent 23e9e52 commit d8b2c7e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
12 changes: 2 additions & 10 deletions src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class BibEntry implements Cloneable {
public static final String OBSOLETE_TYPE_HEADER = "bibtextype";
public static final String KEY_FIELD = "bibtexkey";
public static final String DEFAULT_TYPE = "misc";
protected static final String ID_FIELD = "id";
protected static final String INTERNAL_ID_FIELD = "JabRef-internal-id";
private static final Logger LOGGER = LoggerFactory.getLogger(BibEntry.class);
private static final Pattern REMOVE_TRAILING_WHITESPACE = Pattern.compile("\\s+$");
private final SharedBibEntryData sharedBibEntryData;
Expand Down Expand Up @@ -161,7 +161,7 @@ public void setId(String id) {

String oldId = this.id;

eventBus.post(new FieldChangedEvent(this, BibEntry.ID_FIELD, id, oldId));
eventBus.post(new FieldChangedEvent(this, BibEntry.INTERNAL_ID_FIELD, id, oldId));
this.id = id;
changed = true;
}
Expand Down Expand Up @@ -408,10 +408,6 @@ public Optional<FieldChange> setField(String name, String value, EntryEventSourc
return Optional.empty();
}

if (BibEntry.ID_FIELD.equals(fieldName)) {
throw new IllegalArgumentException("The field name '" + name + "' is reserved");
}

changed = true;

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

if (BibEntry.ID_FIELD.equals(fieldName)) {
throw new IllegalArgumentException("The field name '" + name + "' is reserved");
}

Optional<String> oldValue = getField(fieldName);
if (!oldValue.isPresent()) {
return Optional.empty();
Expand Down
11 changes: 0 additions & 11 deletions src/test/java/org/jabref/model/entry/BibEntryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class BibEntryTest {

Expand All @@ -28,16 +27,6 @@ public void tearDown() {
entry = null;
}

@Test
public void notOverrideReservedFields() {
assertThrows(IllegalArgumentException.class, () -> entry.setField(BibEntry.ID_FIELD, "somevalue"));
}

@Test
public void notClearReservedFields() {
assertThrows(IllegalArgumentException.class, () -> entry.clearField(BibEntry.ID_FIELD));
}

@Test
public void getFieldIsCaseInsensitive() throws Exception {
entry.setField("TeSt", "value");
Expand Down

0 comments on commit d8b2c7e

Please sign in to comment.