From 429ff26d2dd165f50f921846e01a620fdacb736c Mon Sep 17 00:00:00 2001 From: eberhardtj <30794167+eberhardtj@users.noreply.github.com> Date: Wed, 23 May 2018 12:15:45 +0200 Subject: [PATCH 1/2] Fix #278: Receiving leader entity causes exception (cherry picked from commit 264265326fbc5dd9b66fc30d21196d8af1c5e391) --- .../java/org/metafacture/biblio/marc21/Marc21Encoder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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; } From 25f2da3d9a320bae890e7cdeca0ff1a15741150a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=B6hme?= Date: Wed, 19 Dec 2018 14:01:44 +0100 Subject: [PATCH 2/2] Add test-case for issue #278 --- .../biblio/marc21/Marc21EncoderTest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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)); + } + }