aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-12-08 10:03:51 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-12-08 10:03:51 +0100
commitd720b00c9b3b05269f419d3e9f23e1f5bc40505d (patch)
treea64606c297e6c5f1235e75628fe7e5d7a98cb231 /server/sonar-server
parent2fbfee12b562f5fa2c16e3dd9293493678233b52 (diff)
downloadsonarqube-d720b00c9b3b05269f419d3e9f23e1f5bc40505d.tar.gz
sonarqube-d720b00c9b3b05269f419d3e9f23e1f5bc40505d.zip
SONAR-5801 Protect against null file_sources.data column
Diffstat (limited to 'server/sonar-server')
-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>