From 71d3cb157b5c82abd7639b8e6fa2573e6fae24e6 Mon Sep 17 00:00:00 2001 From: Pablissimo Date: Tue, 27 Dec 2016 18:28:28 +0000 Subject: [PATCH] Fix #74, #78 - null pointer exn thrown on no tslint output --- pom.xml | 2 +- .../java/com/pablissimo/sonar/TsLintParserImpl.java | 5 +++++ .../java/com/pablissimo/sonar/TsLintParserTest.java | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3b53d51..faec2b4 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.pablissimo.sonar sonar-typescript-plugin sonar-plugin - 0.96-SNAPSHOT + 0.97-SNAPSHOT TypeScript Analyse TypeScript projects diff --git a/src/main/java/com/pablissimo/sonar/TsLintParserImpl.java b/src/main/java/com/pablissimo/sonar/TsLintParserImpl.java index 864d99e..43390c6 100644 --- a/src/main/java/com/pablissimo/sonar/TsLintParserImpl.java +++ b/src/main/java/com/pablissimo/sonar/TsLintParserImpl.java @@ -23,6 +23,11 @@ public Map> parse(List toParse) { for (String batch : toParse) { TsLintIssue[] batchIssues = gson.fromJson(getFixedUpOutput(batch), TsLintIssue[].class); + + if (batchIssues == null) { + continue; + } + for (TsLintIssue batchIssue : batchIssues) { allIssues.add(batchIssue); } diff --git a/src/test/java/com/pablissimo/sonar/TsLintParserTest.java b/src/test/java/com/pablissimo/sonar/TsLintParserTest.java index ae1ca53..625eb54 100644 --- a/src/test/java/com/pablissimo/sonar/TsLintParserTest.java +++ b/src/test/java/com/pablissimo/sonar/TsLintParserTest.java @@ -67,4 +67,14 @@ public void fixesUpBrokenBatchedOutputFromTsLintPriorTo_4_0_0() { assertEquals(1, issues.size()); assertEquals(2, issues.get("Tools.ts").size()); } + + @Test + public void parseAGoodProjectWithNoIssues() { + List toParse = new ArrayList(); + toParse.add(""); + + Map> issues = new TsLintParserImpl().parse(toParse); + + assertEquals(0, issues.size()); + } }