]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8178 ignore rows with null data
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 30 Sep 2016 08:29:00 +0000 (10:29 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 30 Sep 2016 09:36:55 +0000 (11:36 +0200)
server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java

index e5268e6046881739699294eb6ae52f03c7edca99..53adca4d368718ebdf38d1c512190cf0900ab4dd 100644 (file)
 package org.sonar.server.test.index;
 
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
 import java.io.OutputStreamWriter;
 import java.nio.charset.StandardCharsets;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import javax.annotation.Nullable;
@@ -77,7 +79,13 @@ public class TestResultSetIterator extends ResultSetIterator<Row> {
     String projectUuid = rs.getString(1);
     String fileUuid = rs.getString(2);
     Date updatedAt = new Date(rs.getLong(3));
-    List<DbFileSources.Test> data = FileSourceDto.decodeTestData(rs.getBinaryStream(4));
+    InputStream dataInput = rs.getBinaryStream(4);
+    List<DbFileSources.Test> data;
+    if (dataInput != null) {
+      data = FileSourceDto.decodeTestData(dataInput);
+    } else {
+      data = Collections.emptyList();
+    }
     return toRow(projectUuid, fileUuid, updatedAt, data);
   }
 
index 6e6b5cff38f1ac4847a32bd8ab742a7cd27c309c..5b942c5565c7c576497664cc8a45ad4cb634a21c 100644 (file)
@@ -198,4 +198,16 @@ public class TestResultSetIteratorTest {
     }
   }
 
+  @Test
+  public void read_does_not_fail_if_null_data() throws Exception {
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+    TestTesting.updateDataColumn(dbTester.getSession(), "F1", (byte[])null);
+
+    underTest = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
+
+    FileSourcesUpdaterHelper.Row row = underTest.next();
+    assertThat(row.getFileUuid()).isEqualTo("F1");
+    assertThat(row.getUpdateRequests()).isEmpty();
+    assertThat(underTest.hasNext()).isFalse();
+  }
 }