diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java index 338795696..db0839de8 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java @@ -156,7 +156,9 @@ private void startField(final String name) { @Override public void endEntity() { - builder.endDataField(); + if (state.equals(State.IN_FIELD_ENTITY)) { + builder.endDataField(); + } state = State.IN_RECORD; } diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21EncoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21EncoderTest.java index 411cdd3a2..8317581ad 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21EncoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21EncoderTest.java @@ -15,6 +15,8 @@ */ package org.metafacture.biblio.marc21; +import static org.metafacture.biblio.marc21.Marc21EventNames.LEADER_ENTITY; +import static org.metafacture.biblio.marc21.Marc21EventNames.RECORD_STATUS_LITERAL; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.verify; @@ -35,8 +37,6 @@ */ public final class Marc21EncoderTest { - private static final String LEADER_LITERAL = "leader"; - private Marc21Encoder marc21Encoder; @Mock @@ -102,4 +102,15 @@ public void issue231ShouldIgnoreTypeLiterals() { verify(receiver).process(any(String.class)); } + @Test + public void issue278ShouldNotFailWhenProcessingLeaderEntity() { + marc21Encoder.startRecord(""); + marc21Encoder.startEntity(LEADER_ENTITY); + marc21Encoder.literal(RECORD_STATUS_LITERAL, "a"); + marc21Encoder.endEntity(); + marc21Encoder.endRecord(); + + verify(receiver).process(any(String.class)); + } + }