diff --git a/CHANGELOG.md b/CHANGELOG.md index eb135b3c..f171e9e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,16 @@ Changelog of Git Changelog. ## Unreleased ### No issue +**Checking for null in API-calls** + + * For better error messages. + +[18c745ae65282d7](https://github.com/tomasbjerre/violations-lib/commit/18c745ae65282d7) Tomas Bjerre *2017-08-11 09:42:01* + **Testing with reporter** -[b68214779e22b79](https://github.com/tomasbjerre/violations-lib/commit/b68214779e22b79) Tomas Bjerre *2017-07-14 19:30:01* +[b73430f34a55ff6](https://github.com/tomasbjerre/violations-lib/commit/b73430f34a55ff6) Tomas Bjerre *2017-07-14 19:31:04* ## 1.29 diff --git a/src/main/java/se/bjurr/violations/lib/ViolationsReporterApi.java b/src/main/java/se/bjurr/violations/lib/ViolationsReporterApi.java index c12181b0..27939505 100644 --- a/src/main/java/se/bjurr/violations/lib/ViolationsReporterApi.java +++ b/src/main/java/se/bjurr/violations/lib/ViolationsReporterApi.java @@ -2,6 +2,7 @@ import static java.util.logging.Level.FINE; import static se.bjurr.violations.lib.reports.ReportsFinder.findAllReports; +import static se.bjurr.violations.lib.util.Utils.checkNotNull; import static se.bjurr.violations.lib.util.Utils.setReporter; import java.io.File; @@ -27,17 +28,17 @@ public static ViolationsReporterApi violationsReporterApi() { private ViolationsReporterApi() {} public ViolationsReporterApi findAll(Parser parser) { - this.parser = parser; + this.parser = checkNotNull(parser, "parser"); return this; } public ViolationsReporterApi withReporter(String reporter) { - this.reporter = reporter; + this.reporter = checkNotNull(reporter, "reporter"); return this; } public ViolationsReporterApi inFolder(String folder) { - startFile = new File(folder); + startFile = new File(checkNotNull(folder, "folder")); if (!startFile.exists()) { throw new RuntimeException(folder + " not found"); } @@ -45,15 +46,15 @@ public ViolationsReporterApi inFolder(String folder) { } public List violations() { - List includedFiles = findAllReports(startFile, pattern); + final List includedFiles = findAllReports(startFile, pattern); if (LOG.isLoggable(FINE)) { LOG.log(FINE, "Found " + includedFiles.size() + " reports:"); - for (File f : includedFiles) { + for (final File f : includedFiles) { LOG.log(FINE, f.getAbsolutePath()); } } - List foundViolations = parser.findViolations(includedFiles); - boolean reporterWasSupplied = + final List foundViolations = parser.findViolations(includedFiles); + final boolean reporterWasSupplied = reporter != null && !reporter.trim().isEmpty() && !reporter.equals(parser.name()); if (reporterWasSupplied) { setReporter(foundViolations, reporter); @@ -61,7 +62,7 @@ public List violations() { if (LOG.isLoggable(FINE)) { LOG.log(FINE, "Found " + foundViolations.size() + " violations:"); - for (Violation v : foundViolations) { + for (final Violation v : foundViolations) { LOG.log( FINE, v.getReporter()