aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2019-02-20 10:45:46 +0100
committerSonarTech <sonartech@sonarsource.com>2019-02-22 20:21:10 +0100
commit6f593749e3a6ecd3b01c761692e4e15167ec88ba (patch)
treec69d094d95fc0fb7fa1b5fa60f7b566f7318140e /sonar-scanner-engine
parent7c11a6c444316903bac5fa05e3f986fed20af723 (diff)
downloadsonarqube-6f593749e3a6ecd3b01c761692e4e15167ec88ba.tar.gz
sonarqube-6f593749e3a6ecd3b01c761692e4e15167ec88ba.zip
fixup! SONAR-11741 fix NPE when importing issues from external report
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java52
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java1
2 files changed, 23 insertions, 30 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java
index 468648a3235..f4ff8a26d16 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java
@@ -19,6 +19,7 @@
*/
package org.sonar.scanner.externalissue;
+import com.google.common.base.MoreObjects;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;
@@ -108,41 +109,34 @@ public class ExternalIssueImporter {
@CheckForNull
private static NewIssueLocation fillLocation(SensorContext context, NewIssueLocation newLocation, Location location) {
InputFile file = findFile(context, location.filePath);
- if (file != null) {
- newLocation
- .on(file);
+ if (file == null) {
+ return null;
+ }
+ newLocation.on(file);
- if (location.message != null) {
- newLocation.message(location.message);
- }
+ if (location.message != null) {
+ newLocation.message(location.message);
+ }
- if (location.textRange != null) {
- if (location.textRange.startColumn != null) {
- TextPointer start = file.newPointer(location.textRange.startLine, location.textRange.startColumn);
- int endLine;
- int endColumn;
-
- if (location.textRange.endLine == null) {
- // assume it's on a single line
- endLine = location.textRange.startLine;
- } else {
- endLine = location.textRange.endLine;
- }
- if (location.textRange.endColumn == null) {
- // assume it's until the last character of the end line
- endColumn = file.selectLine(endLine).end().lineOffset();
- } else {
- endColumn = location.textRange.endColumn;
- }
- TextPointer end = file.newPointer(endLine, endColumn);
- newLocation.at(file.newRange(start, end));
+ if (location.textRange != null) {
+ if (location.textRange.startColumn != null) {
+ TextPointer start = file.newPointer(location.textRange.startLine, location.textRange.startColumn);
+ int endLine = MoreObjects.firstNonNull(location.textRange.endLine, location.textRange.startLine);
+ int endColumn;
+
+ if (location.textRange.endColumn == null) {
+ // assume it's until the last character of the end line
+ endColumn = file.selectLine(endLine).end().lineOffset();
} else {
- newLocation.at(file.selectLine(location.textRange.startLine));
+ endColumn = location.textRange.endColumn;
}
+ TextPointer end = file.newPointer(endLine, endColumn);
+ newLocation.at(file.newRange(start, end));
+ } else {
+ newLocation.at(file.selectLine(location.textRange.startLine));
}
- return newLocation;
}
- return null;
+ return newLocation;
}
@CheckForNull
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java
index 152d38002dc..712ac425881 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java
@@ -36,7 +36,6 @@ public class ReportParserTest {
public void parse_sample() {
ReportParser parser = new ReportParser(Paths.get("src/test/resources/org/sonar/scanner/externalissue/report.json"));
- System.out.println(Paths.get("org/sonar/scanner/externalissue/report.json").toAbsolutePath());
Report report = parser.parse();
assertThat(report.issues).hasSize(4);