aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java12
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/source/index/SourceLineResultSetIteratorTest/null-file.xml6
3 files changed, 22 insertions, 0 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java
index e371cc0ff8b..58ad5f49193 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java
@@ -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 {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java
index ccb2584b7d4..17c9998b6e8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java
@@ -111,6 +111,18 @@ public class SourceLineResultSetIteratorTest {
}
@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");
PreparedStatement stmt = connection.prepareStatement("UPDATE file_sources SET data = ? WHERE id=1");
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
index 00000000000..91dafded3dc
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/source/index/SourceLineResultSetIteratorTest/null-file.xml
@@ -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>