From 161cc6f87ab2ea7c275c2a0d9f5d7a35a573cc67 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 30 Sep 2016 10:29:00 +0200 Subject: [PATCH] SONAR-8178 ignore rows with null data --- .../server/test/index/TestResultSetIterator.java | 10 +++++++++- .../server/test/index/TestResultSetIteratorTest.java | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java index e5268e60468..53adca4d368 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java @@ -20,11 +20,13 @@ 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 { String projectUuid = rs.getString(1); String fileUuid = rs.getString(2); Date updatedAt = new Date(rs.getLong(3)); - List data = FileSourceDto.decodeTestData(rs.getBinaryStream(4)); + InputStream dataInput = rs.getBinaryStream(4); + List data; + if (dataInput != null) { + data = FileSourceDto.decodeTestData(dataInput); + } else { + data = Collections.emptyList(); + } return toRow(projectUuid, fileUuid, updatedAt, data); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java index 6e6b5cff38f..5b942c5565c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java @@ -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(); + } } -- 2.39.5