diff --git a/android_app/app/src/main/java/com/health/openscale/core/utils/CsvHelper.java b/android_app/app/src/main/java/com/health/openscale/core/utils/CsvHelper.java index 5403be3f..77161fa8 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/utils/CsvHelper.java +++ b/android_app/app/src/main/java/com/health/openscale/core/utils/CsvHelper.java @@ -33,6 +33,10 @@ public class CsvHelper { } private static String[] getOldStyleHeaders(String sampleLine) { + if (sampleLine == null) { + return null; + } + final String[] fields = sampleLine.split(",", -1); // Return an array with header fields so that all the headers that actually are diff --git a/android_app/app/src/test/java/com/health/openscale/CsvHelperTest.java b/android_app/app/src/test/java/com/health/openscale/CsvHelperTest.java index d801bcb5..d881759b 100644 --- a/android_app/app/src/test/java/com/health/openscale/CsvHelperTest.java +++ b/android_app/app/src/test/java/com/health/openscale/CsvHelperTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import java.io.BufferedReader; import java.io.StringReader; import java.io.StringWriter; +import java.text.ParseException; import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -181,4 +182,10 @@ public class CsvHelperTest { assertEquals(1, list.size()); validateEntry(list.get(0), 0); } + + @Test(expected = ParseException.class) + public void empty() throws Exception { + final String data = ""; + CsvHelper.importFrom(new BufferedReader(new StringReader(data))); + } }