From: Sébastien Lesaint Date: Wed, 28 Sep 2016 15:09:41 +0000 (+0200) Subject: SONAR-8185 FileSourceDao.selectLineHashes supports null in DB X-Git-Tag: 6.1-RC2~4^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=028dbdbd4bd653f3e3beb7b7a8692b0120645da3;p=sonarqube.git SONAR-8185 FileSourceDao.selectLineHashes supports null in DB --- diff --git a/sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java b/sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java index 1ca87ef7103..efc7665bda2 100644 --- a/sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java +++ b/sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java @@ -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) { diff --git a/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java b/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java index 7047b7a34e4..edb21c475ea 100644 --- a/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java @@ -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");