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());
|
writer.write(sb.toString());
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
recordCounter.incrementAndGet();
|
recordCounter.incrementAndGet();
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(new IOException(e));
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,11 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
|
||||||
}
|
}
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
} else {
|
} else {
|
||||||
sb.append("\"").append(escape(o.toString())).append("\"");
|
if (o == null) {
|
||||||
|
sb.append("null");
|
||||||
|
} else {
|
||||||
|
sb.append("\"").append(escape(o.toString())).append("\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c0++;
|
c0++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.xbib.marc.Marc;
|
||||||
|
import org.xbib.marc.MarcXchangeConstants;
|
||||||
import org.xbib.marc.json.MarcJsonWriter;
|
import org.xbib.marc.json.MarcJsonWriter;
|
||||||
import org.xbib.marc.xml.MarcXchangeWriter;
|
import org.xbib.marc.xml.MarcXchangeWriter;
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class MarcWriterTest extends Assert {
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
FileOutputStream out = new FileOutputStream(file);
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
MarcValueTransformers marcValueTransformers = new MarcValueTransformers();
|
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)
|
try (MarcWriter writer = new MarcWriter(out, StandardCharsets.UTF_8)
|
||||||
.setMarcValueTransformers(marcValueTransformers)) {
|
.setMarcValueTransformers(marcValueTransformers)) {
|
||||||
Marc.builder()
|
Marc.builder()
|
||||||
|
@ -98,7 +98,7 @@ public class MarcWriterTest extends Assert {
|
||||||
xmlFile.deleteOnExit();
|
xmlFile.deleteOnExit();
|
||||||
out = new FileOutputStream(xmlFile);
|
out = new FileOutputStream(xmlFile);
|
||||||
marcValueTransformers = new MarcValueTransformers();
|
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)
|
try (MarcXchangeWriter writer = new MarcXchangeWriter(out)
|
||||||
.setMarcValueTransformers(marcValueTransformers)) {
|
.setMarcValueTransformers(marcValueTransformers)) {
|
||||||
Marc.builder()
|
Marc.builder()
|
||||||
|
|
Loading…
Reference in a new issue