diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-11-12 16:07:45 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-11-16 15:12:13 +0100 |
commit | ff15786ca7aa029a1ae4a2ed67f5352a1b03853b (patch) | |
tree | 8092e240908b8514da9ce847d50c7be27983e60d /sonar-plugin-api | |
parent | 9db3683485161ca1a5b786ccbed3144d4daf6610 (diff) | |
download | sonarqube-ff15786ca7aa029a1ae4a2ed67f5352a1b03853b.tar.gz sonarqube-ff15786ca7aa029a1ae4a2ed67f5352a1b03853b.zip |
SONAR-5676 Improve validation of highlighting API
Diffstat (limited to 'sonar-plugin-api')
2 files changed, 13 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java index faf3f7536ec..5dc58102622 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java @@ -79,6 +79,7 @@ public class DefaultHighlighting extends DefaultStorable implements NewHighlight Preconditions.checkState(inputFile != null, "Call onFile() first"); TextRange newRange; try { + Preconditions.checkArgument(startOffset < endOffset, "start offset should be strictly before end offset"); newRange = inputFile.newRange(startOffset, endOffset); } catch (Exception e) { throw new IllegalArgumentException("Unable to highlight file " + inputFile + " from offset " + startOffset + " to offset " + endOffset, e); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlightingTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlightingTest.java index 76378512ff5..dd5ef7bee1b 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlightingTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlightingTest.java @@ -95,6 +95,18 @@ public class DefaultHighlightingTest { } @Test + public void should_prevent_start_equal_end() { + throwable.expect(IllegalArgumentException.class); + throwable + .expectMessage("Unable to highlight file"); + + new DefaultHighlighting(mock(SensorStorage.class)) + .onFile(INPUT_FILE) + .highlight(10, 10, KEYWORD) + .save(); + } + + @Test public void should_prevent_boudaries_overlapping() { throwable.expect(IllegalStateException.class); throwable |