From 028dbdbd4bd653f3e3beb7b7a8692b0120645da3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Wed, 28 Sep 2016 17:09:41 +0200 Subject: [PATCH] SONAR-8185 FileSourceDao.selectLineHashes supports null in DB --- .../org/sonar/db/source/FileSourceDao.java | 7 ++++++- .../sonar/db/source/FileSourceDaoTest.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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"); -- 2.39.5