]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8185 FileSourceDao.selectLineHashes supports null in DB
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 28 Sep 2016 15:09:41 +0000 (17:09 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 28 Sep 2016 15:09:41 +0000 (17:09 +0200)
sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java
sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java

index 1ca87ef71037644a34cadd7a0462f911c2c06966..efc7665bda20b6ddb2c80365d61fa6afe9ed6839 100644 (file)
@@ -26,6 +26,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Collections;
 import java.util.List;
 import javax.annotation.CheckForNull;
 import org.apache.commons.dbutils.DbUtils;
@@ -70,7 +71,11 @@ public class FileSourceDao implements Dao {
       pstmt.setString(2, Type.SOURCE);
       rs = pstmt.executeQuery();
       if (rs.next()) {
-        return END_OF_LINE_SPLITTER.splitToList(rs.getString(1));
+        String string = rs.getString(1);
+        if (string == null) {
+          return Collections.emptyList();
+        }
+        return END_OF_LINE_SPLITTER.splitToList(string);
       }
       return null;
     } catch (SQLException e) {
index 7047b7a34e4b633464a0a3aaa8592f06292716d4..edb21c475ea1c1d52b9e6792dd2ccccfc7d91c22 100644 (file)
@@ -108,6 +108,25 @@ public class FileSourceDaoTest {
       "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type", "revision");
   }
 
+  @Test
+  public void selectLineHashes_does_not_fail_when_lineshashes_is_null() {
+
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+    underTest.insert(new FileSourceDto()
+        .setProjectUuid("PRJ_UUID")
+        .setFileUuid("FILE2_UUID")
+        .setBinaryData("FILE2_BINARY_DATA".getBytes())
+        .setDataHash("FILE2_DATA_HASH")
+        .setSrcHash("FILE2_HASH")
+        .setDataType(Type.SOURCE)
+        .setCreatedAt(1500000000000L)
+        .setUpdatedAt(1500000000001L)
+        .setRevision("123456789"));
+
+    assertThat(underTest.selectLineHashes(dbTester.getSession(), "FILE2_UUID")).isEmpty();
+  }
+
   @Test
   public void update() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");