fix NPE in JSON writer

This commit is contained in:
Jörg Prante 2016-09-19 11:57:35 +02:00
parent dcbe694669
commit a98816e315
3 changed files with 11 additions and 5 deletions

View file

@ -156,8 +156,8 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
writer.write(sb.toString());
sb.setLength(0);
recordCounter.incrementAndGet();
} catch (IOException e) {
handleException(e);
} catch (Exception e) {
handleException(new IOException(e));
} finally {
lock.unlock();
}
@ -312,9 +312,13 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
c00++;
}
sb.append("]");
} else {
if (o == null) {
sb.append("null");
} else {
sb.append("\"").append(escape(o.toString())).append("\"");
}
}
c0++;
}
sb.append('}');

View file

@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.xbib.marc.Marc;
import org.xbib.marc.MarcXchangeConstants;
import org.xbib.marc.json.MarcJsonWriter;
import org.xbib.marc.xml.MarcXchangeWriter;

View file

@ -82,7 +82,7 @@ public class MarcWriterTest extends Assert {
file.deleteOnExit();
FileOutputStream out = new FileOutputStream(file);
MarcValueTransformers marcValueTransformers = new MarcValueTransformers();
marcValueTransformers.setMarcValueTransformer("245$10$a", t -> t.replaceAll("Chabon","Chibon"));
marcValueTransformers.setMarcValueTransformer("245$10$a", t -> t.replaceAll("Chabon", "Chibon"));
try (MarcWriter writer = new MarcWriter(out, StandardCharsets.UTF_8)
.setMarcValueTransformers(marcValueTransformers)) {
Marc.builder()
@ -98,7 +98,7 @@ public class MarcWriterTest extends Assert {
xmlFile.deleteOnExit();
out = new FileOutputStream(xmlFile);
marcValueTransformers = new MarcValueTransformers();
marcValueTransformers.setMarcValueTransformer("245$10$a", t -> t.replaceAll("Chibon","Chabon"));
marcValueTransformers.setMarcValueTransformer("245$10$a", t -> t.replaceAll("Chibon", "Chabon"));
try (MarcXchangeWriter writer = new MarcXchangeWriter(out)
.setMarcValueTransformers(marcValueTransformers)) {
Marc.builder()