Fix nullpointer exception in CSV exporter

Change-Id: Ie49251f79c2fe5b1b702375b8776180bd2112c63
diff --git a/Changes b/Changes
index 4a9fcdd..920712c 100644
--- a/Changes
+++ b/Changes
@@ -1,7 +1,8 @@
-0.2.4 2021-04-27
+0.2.4 2021-04-28
     - Fix temporary session-riding capabilities.
     - Introduced central tinylog.
     - Fix nullpointer in RTF export.
+    - Fix nullpointer in CSV export.
 
 0.2.3 2021-03-24
     - Added trail info to RTF export.
\ No newline at end of file
diff --git a/src/main/java/de/ids_mannheim/korap/plkexport/CsvExporter.java b/src/main/java/de/ids_mannheim/korap/plkexport/CsvExporter.java
index 0b62ff4..111bc45 100644
--- a/src/main/java/de/ids_mannheim/korap/plkexport/CsvExporter.java
+++ b/src/main/java/de/ids_mannheim/korap/plkexport/CsvExporter.java
@@ -98,6 +98,8 @@
      * Add a CSV cell to the CSV row
      */
     private void addCell (Writer w, String s) throws IOException {
+        if (s == null)
+            return;
 
         // If meta characters exist, make a quote
         if (s.contains(",")  ||
diff --git a/src/test/java/de/ids_mannheim/korap/plkexport/CsvExporterTest.java b/src/test/java/de/ids_mannheim/korap/plkexport/CsvExporterTest.java
index 4cacacc..17648ea 100644
--- a/src/test/java/de/ids_mannheim/korap/plkexport/CsvExporterTest.java
+++ b/src/test/java/de/ids_mannheim/korap/plkexport/CsvExporterTest.java
@@ -56,6 +56,28 @@
         assertEquals(lines[1],",Simple,match1,Snippet,,,RTF/G59/34284,Goethe,20051103,Title1");
         assertEquals(lines[2],"...,\"Simpler, \"\"faster\"\"\",\"\"\"match2\"\"\",Snippet,...,,RTF/G59/34285,Schiller,20051104,\"Title2, the\"");
         assertEquals(lines.length,3);
+
+        csv = new CsvExporter();
+        csv.init("{\"matches\":["+
+                 "{\"title\":\"Title1\","+
+                 "\"pubDate\":\"20051103\","+
+                 "\"textSigle\":\"RTF/G59/34284\","+
+                 "\"snippet\":\"Simple <mark>match1</mark> Snippet\"}"+
+                 ","+
+                 "{\"author\":\"Schiller\","+
+                 "\"title\":\"Title2, the\","+
+                 "\"pubDate\":\"20051104\","+
+                 "\"textSigle\":\"RTF/G59/34285\","+
+                 "\"snippet\":\"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>"+
+                 "Simpler, \\\"faster\\\" </span><span class=\\\"match\\\"><mark>&quot;match2&quot;</mark></span>"+
+                 "<span class=\\\"context-right\\\"> Snippet"+
+                 "<span class=\\\"more\\\"></span></span>\"}"+
+                 "]}");
+        csv.finish();
+        resp = csv.serve().build();
+        x = (String) resp.getEntity();
+        resp.close();
+
     };
 
     @Test