fix NPE in JSON writer
This commit is contained in:
parent
dcbe694669
commit
a98816e315
3 changed files with 11 additions and 5 deletions
|
@ -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();
|
||||
}
|
||||
|
@ -313,7 +313,11 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
|
|||
}
|
||||
sb.append("]");
|
||||
} else {
|
||||
sb.append("\"").append(escape(o.toString())).append("\"");
|
||||
if (o == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append("\"").append(escape(o.toString())).append("\"");
|
||||
}
|
||||
}
|
||||
c0++;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue