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()); 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();
} }
@ -312,9 +312,13 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
c00++; c00++;
} }
sb.append("]"); sb.append("]");
} else {
if (o == null) {
sb.append("null");
} else { } else {
sb.append("\"").append(escape(o.toString())).append("\""); sb.append("\"").append(escape(o.toString())).append("\"");
} }
}
c0++; c0++;
} }
sb.append('}'); sb.append('}');

View file

@ -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;