]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5801 Protect against null file_sources.data column
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 8 Dec 2014 09:03:51 +0000 (10:03 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 8 Dec 2014 09:03:51 +0000 (10:03 +0100)
server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java
server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java
server/sonar-server/src/test/resources/org/sonar/server/source/index/SourceLineResultSetIteratorTest/null-file.xml [new file with mode: 0644]

index e371cc0ff8b6f6b07aaed6a43de32132c468c726..58ad5f491934b4ead3e94ca7520ef530de48557c 100644 (file)
@@ -119,6 +119,10 @@ public class SourceLineResultSetIterator extends ResultSetIterator<SourceLineRes
     SourceFile result = new SourceFile(fileUuid, updatedAt);
 
     Reader csv = rs.getCharacterStream(4);
+    if (csv == null) {
+      return result;
+    }
+
     int line = 1;
     CSVParser csvParser = null;
     try {
index ccb2584b7d473c834e4a44f918b15be60ae8308f..17c9998b6e8c5d6d63a03bca2f4d4f38d4467c70 100644 (file)
@@ -110,6 +110,18 @@ public class SourceLineResultSetIteratorTest {
     iterator.close();
   }
 
+  @Test
+  public void parse_null_file() throws Exception {
+    db.prepareDbUnit(getClass(), "null-file.xml");
+
+    SourceLineResultSetIterator iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L);
+    assertThat(iterator.hasNext()).isTrue();
+    SourceLineResultSetIterator.SourceFile file = iterator.next();
+    assertThat(file.getFileUuid()).isEqualTo("uuid-MyFile.xoo");
+    assertThat(file.getLines()).isEmpty();
+    iterator.close();
+  }
+
   @Test
   public void should_fail_on_bad_csv() throws Exception {
     db.prepareDbUnit(getClass(), "shared.xml");
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/index/SourceLineResultSetIteratorTest/null-file.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/index/SourceLineResultSetIteratorTest/null-file.xml
new file mode 100644 (file)
index 0000000..91dafde
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+
+  <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="1416238020000" updated_at="1416239042000"
+                data="[null]" data_hash="" />
+
+</dataset>