diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-02-12 15:36:13 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-02-12 15:36:13 +0100 |
commit | 8ea9993161abfdfd439b26fd07d6fc5479a8fdb0 (patch) | |
tree | 3254bf48e6ee05920e45c18e5bd3b4520f862515 /sonar-batch/src/main | |
parent | a508911239639061a054d45b47f6a7b075927b2e (diff) | |
download | sonarqube-8ea9993161abfdfd439b26fd07d6fc5479a8fdb0.tar.gz sonarqube-8ea9993161abfdfd439b26fd07d6fc5479a8fdb0.zip |
Ignore source file information that is set on an unknown line
Diffstat (limited to 'sonar-batch/src/main')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java index 3475e9f6046..aa61c83c77e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java @@ -50,7 +50,7 @@ import java.util.List; import java.util.Map; /** - * Consolidate different caches for the export of report to server. + * Consolidate different caches for the export of file sources to server. * @see org.sonar.server.source.db.FileSourceDb */ public class SourceDataFactory implements BatchComponent { @@ -175,10 +175,13 @@ public class SourceDataFactory implements BatchComponent { for (Measure measure : measures) { Map<Integer, String> lineMeasures = KeyValueFormat.parseIntString((String) measure.value()); for (Map.Entry<Integer, String> lineMeasure : lineMeasures.entrySet()) { - String value = lineMeasure.getValue(); - if (StringUtils.isNotEmpty(value)) { - FileSourceDb.Line.Builder lineBuilder = to.getLinesBuilder(lineMeasure.getKey() - 1); - op.apply(value, lineBuilder); + int lineIdx = lineMeasure.getKey(); + if (lineIdx <= to.getLinesCount()) { + String value = lineMeasure.getValue(); + if (StringUtils.isNotEmpty(value)) { + FileSourceDb.Line.Builder lineBuilder = to.getLinesBuilder(lineIdx - 1); + op.apply(value, lineBuilder); + } } } } @@ -290,8 +293,8 @@ public class SourceDataFactory implements BatchComponent { } private <G> void writeItem(G item, StringBuilder[] dataPerLine, int currentLineIdx, long startLineOffset, long endLineOffset, RangeItemWriter<G> writer) { - if (startLineOffset == endLineOffset) { - // Do not store empty items + if (startLineOffset == endLineOffset || currentLineIdx > dataPerLine.length) { + // empty items or bad line index return; } if (dataPerLine[currentLineIdx - 1] == null) { @@ -363,8 +366,10 @@ public class SourceDataFactory implements BatchComponent { private void addBlock(int blockId, DuplicationGroup.Block block, FileSourceDb.Data.Builder to) { int currentLine = block.startLine(); for (int i = 0; i < block.length(); i++) { - to.getLinesBuilder(currentLine-1).addDuplications(blockId); - currentLine++; + if (currentLine <= to.getLinesCount()) { + to.getLinesBuilder(currentLine - 1).addDuplications(blockId); + currentLine++; + } } } } |